views:

171

answers:

1

Hi All,

I have a javascript class with methods and properties.

Is it possible to wire this class up to a pageunload event?

I am trying to call a method in my class when the user moves pages.

How can I do this.

Thanks

A: 

Returning a string from the onbeforeunload event handler will show a dialog box.

<html>
<head>
</head>
<body>
test
<script>
window.onbeforeunload = function () {
   return "*** Warning: changes are not saved! ***";
};
</script>
</body>
</html>

In internet explorer this dialog looks like this:

---------------------------
Windows Internet Explorer
---------------------------
Are you sure you want to navigate away from this page?

*** Warning: changes are not saved! ***

Press OK to continue, or Cancel to stay on the current page.
---------------------------
OK   Cancel   
---------------------------

Your text will be sandwiched between some browser specific text, but that is the only way.

Kristof Neirynck
How do I do this in a class that the class responds to the unload event?
SetiSeeker
Can you tell me how you create your "class"? Do you use a framework, or just a function closure or an object with properties? Add some example code to your question and I'll use it in my answer.
Kristof Neirynck