开发者

How do I keep the user from closing the window?

开发者 https://www.devze.com 2023-04-04 12:14 出处:网络
I am using the following code to try to make an \"unclosable\" HTML page. function pass(){ var ansf=prompt (\"Password Required\", \"Password\");

I am using the following code to try to make an "unclosable" HTML page.

function pass(){ 
var ansf=prompt ("Password Required", "Password");
if (ansf=="asjdfhasdijf") alert("Password Accepted");
else (pass());
}

The HTML involved with this looks like this:

<body onUnload="pass()">

I'm not sure why this isn't working, it used to (abou开发者_开发问答t 1 year ago).

I apologize if this is a stupid question, I haven't worked with JavaScript for at least a year (and even then I knew very little).


It will work if you do this:

function pass(){ 

    var ansf=prompt ("Password Required", "Password");
    if (ansf=="asjdfhasdijf") alert("Password Accepted");
    else (pass());

}
window.onbeforeunload = pass;

Here's a demo: http://jsfiddle.net/khxM7/ I've made it easy to exit if anyone is worried.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号