1

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

4
  • Works fine for me: jsfiddle.net/gilly3/qmfMd/1.
    – gilly3
    Commented Sep 14, 2011 at 0:19
  • 2
    Prevent this page from creating additional dialogs [] Current browser design will never allow an "unclosable page" Commented Sep 14, 2011 at 0:23
  • Yeah, this doesn't really work. Plus, if you actually made my browser uncloseable, I'd make your server go away. Commented Sep 14, 2011 at 0:49
  • This was just for kicks and giggles. You can also easily close this with Task Manager... Commented Sep 14, 2011 at 0:54

1 Answer 1

6

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.

4
  • 3
    All I did was click the box that said "prevent this site from creating more dialogs" ;) Commented Sep 14, 2011 at 0:18
  • you've got to be kidding me... what will they think of next 9_9 Commented Sep 14, 2011 at 0:19
  • This is blocked by modern browsers. How do you fix it? Make an actual function, and make another function that just runs setTimeout(actualFunction, 1). Set window.onbeforeunload = callActualFunction; and that way it'll work...
    – KTibow
    Commented Jun 5, 2020 at 19:57
  • Also to bypass prevent this site from creating more dialogs, use a window.open and set the href to something like javascript:document.write("<h1>Your single line only HTML</h1>"). You can try to communicate using window.opener...
    – KTibow
    Commented Jun 5, 2020 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.