我正在创建一个站点,它需要一个密码进入它,但一旦密码提示符打开,这是太困难(不方便用户)返回。密码的目的是防止用户看到页面和页面源。
以下是我到目前为止所得到的:
do{
$('html').hide(); //hiding html with jQuery
var pass = "password"; //setting password
var selection = prompt("Enter password", ""); //prompting for password
if(selection == "cancel"){
window.location.href = "http://www.example.com/";
}; //trying (unsuccesfully) to make the page redirect if user answers "cancel"
} while(selection!=pass);发布于 2016-07-30 21:42:14
来自https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt
If the user clicks the Cancel button, this function returns null.
所以,
do{
$('html').hide();
var pass = "password";
var selection = prompt("Enter password", "");
if(selection === null) {
window.location.href = "http://www.example.com/";
break;
};
} while(selection !== pass);您需要中断语句,因为如果仍然有代码运行,浏览器将不会重定向,就像这里的while循环一样。
https://stackoverflow.com/questions/38678591
复制相似问题