"Martin Honnen" <ma*******@yahoo.de> wrote in message news:40********@olaf.komtel.net...
|
|
| Mozzie ³ »( òvó )« »( òvó )« T wrote:
|
| > Can 'onbeforeunload' (ie) be used to trigger a javascript?
| >
| > I can't find any info on how or if this is possible.
|
| Yes, sure, the following inserts a warning message into the page with
| both IE 6 and Mozilla 1.7 for me if I try to navigate away from the page
| so script is executed:
|
| <html>
| <head>
| <title>calling script in the beforeunload event handler</title>
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
| <script type="text/javascript">
| function showWarning (message) {
| var p;
| if (document.createElement && (p = document.createElement('p'))) {
| p.className = 'warning';
| p.appendChild(document.createTextNode(message));
| document.body.insertBefore(p, document.body.firstChild);
| }
| }
|
| window.onbeforeunload = function (evt) {
| showWarning('Are you sure you want to leave this page?');
| if (!evt) {
| evt = window.event;
| }
| if (evt) {
| evt.returnValue = 'Are you sure you want to leave this page?';
| return evt.returnValue;
| }
| }
| </script>
| <style type="text/css">
| p.warning {
| color: red;
| background-color: white;
| font-weight: bold;
| font-size: 110%;
| }
| </style>
| </head>
| <body>
| <p>
| Visit
| <a href="http://JavaScript.FAQTs.com/">JavaScript.FAQTs</a>.
| </p>
| </body>
| </html>
|
|
| --
|
| Martin Honnen
|
http://JavaScript.FAQTs.com/
|
Thanks for your help :-)
Regards.