以编程性评论和删除JavaScript功能
我有一个问题。我有这个逻辑:我有一个 javascript 文件,其中包含条件**如果** x = 0 load ** index.html ** else load ** index1.html* *
。现在, index.html 和 index1.html 是相同的,并且两个负载均相同的 javascript 文件,该文件包含一个应为条件<代码> x = 0 将用户带到应用程序,但需要限制x = 1
时的某些操作。我只是想知道是否可能在决定采用这种方法或完全改变我需要做的事情的逻辑之前是否有可能。还有另一种方法,创建两个版本的 javaScript 文件,但是它将代表大量重复的文件,因为该评论和不受调的功能在应用程序上的多个位置中都存在,并且它是我认为,一个 MVC 项目比包含函数本身的文件要复制更多。
这个想法是,我将为一个计划提供两个计划,即免费计划和a pro计划。它们之间的独特区别是对某些功能的限制。因此,我拥有此功能:
if(userActive.isPro){
var payActive = JSON.parse(localStorage.getItem("payActive"));
if(payActive){
if(parseInt(payActive.status) === 1){
window.location.href= '../app/index.html';
}
}
else{
window.location.href= '../app/index1.html';
}
}
这是使每个计划有所不同的功能。
function openAddPopup() {
//check first if user is PRO Copy
const userStatus = localStorage.getItem("userKind");
const user = userStatus;
if (user) {
app.router.load('contactEdit', { 'isFavorite': state.isFavorite });
} else {
alert("You can only add 3 elements on the free version");
}
}
对于 Pro Plan ,我需要执行该应用程序的完整版本,对于免费计划然后是受限版本。
因此,是否可以将 javascript 函数附加到 index.html 和 index1.html 的情况下,要进行第二次,但是,如果 Pro Plan ,第一个?
I have a question. I have this logic in mind: I got a JavaScript file which contains a condition **if** x = 0 load **index.html** else load **index1.html**
. Now, index.html and index1.html are identical and both loads the same JavaScript file which contains a function which should, for the condition x = 0
take the user to the app but need to restrict some actions when x = 1
. I'm just trying to know if it is even possible before I decide if I take this approach or completely change the logic of what I need to do. There is another way, creating two versions of the JavaScript file, but it would represent a significant amount of duplicated files as this commented and uncommented functions are present in more than one place on the app and as it is an MVC project I would have, I think, to duplicate more than the file which contains the function itself.
The idea is that I'm going to serve an app with two plans, a FREE plan and a PRO plan. The unique difference between them is a restriction on certain functionalities. So I have this function:
if(userActive.isPro){
var payActive = JSON.parse(localStorage.getItem("payActive"));
if(payActive){
if(parseInt(payActive.status) === 1){
window.location.href= '../app/index.html';
}
}
else{
window.location.href= '../app/index1.html';
}
}
And this is the function which makes the difference for each plan.
function openAddPopup() {
//check first if user is PRO Copy
const userStatus = localStorage.getItem("userKind");
const user = userStatus;
if (user) {
app.router.load('contactEdit', { 'isFavorite': state.isFavorite });
} else {
alert("You can only add 3 elements on the free version");
}
}
For the PRO plan I need to execute the full version of the app and for the FREE plan then the restricted version.
So, is it possible to append a JavaScript function to index.html and index1.html to, in case of the FREE plan, to do the second, but, in case of the PRO plan, the first?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要我今天早上醒来时就牢记一个简单的解决方案,并想与社区分享。
在
index.html
中,我说:因此,在
index1.html
中:然后在
app.html
中?当 auth api 将用户发送到应用程序时,如果它是Pro用户,则 api 将他/她重定向到
index.html
存储在localstorage
userkind
带有** pro **
值的变量,但是如果它是标准用户,则API将其重定向她到index1.html
userkind
localstorage
中的变量。这样可以确保如果用户的失去这种情况,他/她就可以访问标准版本。这是一个工作示例:
index.html
运行<代码> index.html ,然后
index1.html
,因为您将充当auth API。然后评论是否可以或必须改进。
As long as I woke up this morning with a simple solution in mind and want to share it with the community.
In the
index.html
I put this:So, in the
index1.html
this:Then in the
app.html
this:How it works? When the Auth API send the user to the App, if it is a PRO user the API redirects him/her to the
index.html
which stores inlocalStorage
theuserKind
variable with a**PRO**
value, but if it is a Standard user, then the API redirects him/her to theindex1.html
which delete theuserKind
variable inlocalStorage
. This way it is ensured that if user is PRO loses this condition, he/her just can access to the Standard version.Here is a working example:
index.html
Run
index.html
and thenindex1.html
, as you are going to function as the Auth API.Then comment if it is ok or have to be improved.