please delete me
please delete me

Reputation: 809

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 (about 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).

Upvotes: 1

Views: 3126

Answers (1)

Joe
Joe

Reputation: 82604

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.

Upvotes: 6

Related Questions