I am implementing a popup with javascript which fire when the page is closed . I am using the unload() page handler. The problem is that the popup does not stays ... it popups for a while but then the new page loads.

I want it to stay there until user presses cancel..


7 Years
Discussion Span
Last Post by almostbob

Give me some code please. I don't think it dissapeares like that. I implemented once something like that and it worked well for me. Some code should help me help you :).


you actually want your site blacklisted
you want to open a window to override user actions
Not a particularly good idea


actually it is not a window it is an iframe pop up.. like saying GoodBye to user...
Actually i am firing a function to show a MOOdle popup.
Here is the code.
I donot know whats wrong with it..

It starts to appear and then vanishes.


<script type="text/javascript" src="javascript/moodalbox121compressed/js/mootools.js"></script>
<script type="text/javascript" src="javascript/moodalbox.js"></script>
<script type="text/javascript" src="javascript/modalbox.js"></script>
<link href="javascript/moodalbox.css" rel="stylesheet" type="text/css" media="screen">
<script type="text/javascript">
window.onbeforeunload = popup;
function popup(){
MOOdalBox.open( "popup.htm","Some kind of caption", "450 305" )


Edited by darktangent: n/a


Well, it's all about how that moodle dialog works. I was talking about unload event on <body> and use of an alert() message. Try using window.stop() function from javascript (to stop the browser) and after you press OK or close the dialog use window.location.href="new_location" to redirect the browser. I can be wrong.. stop doesn't always work on all browsers... but I try to help somehow :).


the window.stop also does not works...
The popup loads but there is just a flash and then it vanishes...
I want it to load completely.


why an external file
could you use unload to change the visibility of a layer in the page's css without the extra time needed to download the file

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.