Jump to content

problem with alert on window unload


vinpkl

Recommended Posts

hi all

 

i am facing trouble in calling function on window unload.

 

<script language="javascript">
window.onunload = function() 
{  
alert("bye");
}
</script>

 

i want to call this script only when the user closed the browser tab. but i m getting this alert on every refresh and when i leave this page and click another buton link page.

 

means i have this script on my index page and when i leave it go to contact us page then also i get this alert and everytime i refresh the page.

 

how can i get this alert only when i close the browser tab.

 

vineet

Link to comment
https://forums.phpfreaks.com/topic/133777-problem-with-alert-on-window-unload/
Share on other sites

hi porjectfear

 

have u tried it. if yes then plz tell me.

 

i m trying it in IE7 and Firefox 3 and its not working on both browsers. Not getting any alert on refresh and not getting any alert on closing window.

 

<script language="javascript">
window.onclose = function()
{
alert("do you want to exit");
}
</script>

 

vineet

<script language="javascript">
var displayPrompt=true;
</script>

<script language="JavaScript" event="onbeforeunload()" for="window">
if (displayPrompt){
event.returnValue = "If you leave now, your answers will be lost. If you intend to return to the survey,\npelease use the pause button at the end of each page.";
}
</script>

 

then in all your links... that you dont want this to pop up on  use this below??

 

<a href="LINKSURL" onclick="displayPrompt=false">link</a>

hi drop faith

 

this code displays alert on every refresh. what can we do for it. is there any solution. can ajax or anyother language help us. i m using it in IE7.

 

<script language="javascript">
var displayPrompt=true;
</script>

<script language="JavaScript" event="onbeforeunload()" for="window">
if (displayPrompt){
event.returnValue = "If you leave now, your answers will be lost. If you intend to return to the survey,\npelease use the pause button at the end of each page.";
}
</script>

 

THANKS

VINEET

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.