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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onbeforeunload Sample

Status
Not open for further replies.

mwolf00

Programmer
Nov 5, 2001
4,177
US
Several times, I've heard people how to detect someone leaving a page BEFORE they actually leave... In Internet Explorer, you can use this!!!

From:


<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<TITLE>onbeforeunload Sample</TITLE>

<SCRIPT>
function closeIt()
{
event.returnValue = &quot;Any string value here will force a dialog box to appear before closing the window.&quot;;
}

</SCRIPT>

</HEAD>

<BODY onbeforeunload=&quot;closeIt()&quot;>

<H1>onbeforeunload Sample</H1>

<P>This example uses the onbeforeunload event to ask users whether they want to remain on the current page
or navigate to a new URL. When the user clicks on the hyperlink or attempts to close the browser window,
the onbeforeunload event fires on the body and a dialog box appears. If the user chooses 'OK',
the page navigates to the new URL ( or closes the window;
if the user chooses 'Cancel', the page remains the same.</P>

<a href=&quot; here to navigate to </BODY>
</HTML>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
That is sooooo annoying. I persoally hate it when some websites think they have to ask me if you really want to leave the site. As if i'm such a novice that I didn't know what the &quot;X&quot; might do, lol...

If I click the X on the browser window, obviously I want out. As for linnking, why not simply use the &quot;target&quot; attribute??

I have this little thing, Advanced Delusionary Schizophrenia with Involuntary Narcissistic Rage. It's no big deal really...
 
GUJUm0deL -

For me, this is very handy for intranet use. There are people in my office who will make changes to a form, not save them and expect the changes to be made on the DB... Using this, I can detect that a form was changed and gently remind them that they need to save their changes if they want to keep them.

The people in my office are the reason for the quote I have in my signature...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Yeah, I don't really think that onbeforeunload is used to dummy-proof against the developers, it's used to dummy-proof against all the morons you write the code for.

-kaht

banghead.gif
 
mwolf00,

<joke>
The people in your office were very mad when they heard about the quote. They're on their way to kill you. But that is after you finished all the programming jobs they requested you to do.
</joke> ;-)
 
i tried using onbeforeunload

as following
<script language=&quot;javascript&quot;>
function dummy(){
event.returnValue = 'You may lose unsaved data. '
}
</script>

<body onBeforeUnload=&quot;dummy();&quot;>

The problem is i am getting two pop-up messages when i hit 'OK'.

This does not happen on 'Cancel'

i am using IE6.0

Thank you,
Diwakar.K


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top