HighDots Forums  

onbeforeunload

Javascript (German) Programmiersprache JavaScript. (de.comp.lang.javascript)


Discuss onbeforeunload in the Javascript (German) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Stephan Dreisbach
 
Posts: n/a

Default onbeforeunload - 12-23-2007 , 06:12 AM






Hallo,
auf einer Kinderseite will ich verhindern, dass die Seite verlassen
wird, ohne dass eine bestimmte Aufgabe erledigt ist. Das funktioniert
auch, aber:
Ich möchte den Aufruf der eigenen Seite, veranlasst durch ein Formular
und php_self davon ausdrücklich ausschließen. Gibt es da eine
Möglichkeit? OnBeforeUnload soll also prüfen, ob das nicht die eigene
Seite ist.
--
Stephan

Reply With Quote
  #2  
Old   
Martin Honnen
 
Posts: n/a

Default Re: onbeforeunload - 12-23-2007 , 06:43 AM






Stephan Dreisbach wrote:

Quote:
Ich möchte den Aufruf der eigenen Seite, veranlasst durch ein Formular
und php_self davon ausdrücklich ausschließen. Gibt es da eine
Möglichkeit? OnBeforeUnload soll also prüfen, ob das nicht die eigene
Seite ist.
Setze eine Variable, wenn das Formular verschickt wird, prüfe diese in
onbeforeunload:

<script type="text/javascript">
var formSubmit = false;
</script>

<body onbeforeunload="if (!formSubmit) {
event.returnValue = "warning";
}
formSubmit = false;">

<form onsubmit="window.formSubmit = true;
return true;"
...>

--

Martin Honnen
http://JavaScript.FAQTs.com/


Reply With Quote
  #3  
Old   
Stephan Dreisbach
 
Posts: n/a

Default Re: onbeforeunload - 12-23-2007 , 07:42 AM



Martin Honnen <mahotrash (AT) yahoo (DOT) de> schrieb:

[..]
Quote:
Setze eine Variable, wenn das Formular verschickt wird, prüfe diese in
onbeforeunload:

script type="text/javascript"
var formSubmit = false;
/script

body onbeforeunload="if (!formSubmit) {
event.returnValue = "warning";
}
formSubmit = false;"

form onsubmit="window.formSubmit = true;
return true;"
...
Danke für den Hinweis.
Es geht noch einfacher: Ich setze per onsubmit den Eventhandler
einfach auf null:
<form .... onsubmit="window.onbeforeunload=null;">
--
Stephan


Reply With Quote
  #4  
Old   
manuzziman@gmail.com
 
Posts: n/a

Default Re: onbeforeunload - 01-17-2008 , 11:53 AM



Quote:
Danke für den Hinweis.
Es geht noch einfacher: Ich setze per onsubmit den Eventhandler
einfach auf null:
form .... onsubmit="window.onbeforeunload=null;"
--
Stephan
Ich glaube das funktioniert nicht im IE

Wass wohl functioniert in IE und FF:

<script type="text/javascript">
isSolved = false;
function allSolved(){
isSolved = true;
}

function unloadMess(){
mess = "Warte! Du hasst deine Augabe nicht erledigt."
if(!isSolved) return mess;
}
window.onbeforeunload=unloadMess;
</script>

<form .... onsubmit="allSolved()"



gefunden im: http://www.webreference.com/dhtml/di.../bunload4.html


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.