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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.