How do I keep the user from closing the window?
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.
精彩评论