Link to home
Create AccountLog in
Avatar of Yo-NuTZ
Yo-NuTZ

asked on

onbeforeunload event triggered unnecesarily when writing into div with .innerHTML

Hello,

I'm having a problem with the window.onbeforeunload Javascript event. When i add to the page an area where onclick i open up a form (to submit data via ajax) written with div.innerHTML and making it visible through display:block (css property), well then the onbeforeunload event is triggered wrongly (only in Internet Explorer) on writing into a div.
I tried using a guard boolean variable, it didn't work. I tried resetting the onbeforeunload with null and then reassigning, it didn't work (when i say it didn't work it means that the same onbeforeunload event is still triggered when it shouldn't.

Any help in solving this or finding a workaround would ne excellent.
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Yo-NuTZ
Yo-NuTZ

ASKER

I can't believe it, it really works. You'll have the points by the end of the day, i want to properly test it and right now i don't have access to the server. But how come? Can you please explain how this works behind, so far i've been using return false only for forms i didn't want submitted (ajax and checking purposes).

Oh and actually, right now i have <a href="javascript://" onClick="showHide(2); return false"> (# doesn't suit me as it moves the focus of the page to the zone of the anchor or top)
the # is a placeholder

If the onclick returns false - and note that it will get to the return false ONLY if the function called does not give an error - the href itself is ignored

So only if you have an error in the function,  the link to the anchor will be executed...


Michel

A better href than javascript://
is
href="javascript:void(0)"

Michel
Avatar of Yo-NuTZ

ASKER

i totally forgot, i'm very sorry, here are your points
No problem.
Thanks