Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onbeforeunload and links 1

Status
Not open for further replies.

pfrancis

Programmer
Mar 18, 2004
19
US
Ok. I did a search to figure out how to stop a window from closing and I found the onbeforeunload with the dialog box. This works to stop the window from closing, but if a link is clicked it still goes through the unload and still prompts, even though the window isn't closing. Is there a way to use the onbeforeunload to stop the window from closing, but still allow for links to be used? Thanks for the help.
 
How about something like this?
Code:
<a href="page.html" onclick="document.onbeforeunload=''">

You could probably add it to every link on the page at onload by looping through the links array.

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
Thanks adam0101 for your help, but that didn't work. It did make me find another way to do it though. Here is what I used.

This is at the top of the page:
Code:
<script language="javascript">
ClosingVar = true
window.onbeforeunload = ExitCheck;
function ExitCheck()
{
if (ClosingVar == true) {
	ExitCheck = false
	return "This is the message.";   
}
}
</script>

This is how my links look:
Code:
<a href="page.html" onClick="ClosingVar=false">

Hopefully it will help someone else too.
Again, Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top