×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

onbeforeunload Sample

onbeforeunload Sample

onbeforeunload Sample

(OP)
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:
http://msdn.microsoft.com/workshop/samples/author/dhtml...


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

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

</SCRIPT>

</HEAD>

<BODY onbeforeunload="closeIt()">

<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 (www.microsoft.com) or closes the window;
 if the user chooses 'Cancel', the page remains the same.</P>

<a href="http://www.microsoft.com">Click here to navigate to www.microsoft.com</a>;
</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)


RE: onbeforeunload Sample

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 "X" might do, lol...

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

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

RE: onbeforeunload Sample

(OP)
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)


RE: onbeforeunload Sample

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

RE: onbeforeunload Sample

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>

RE: onbeforeunload Sample

i tried using onbeforeunload

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

<body onBeforeUnload="dummy();">

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


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close