Solved

onbeforeunload event triggered unnecesarily when writing into div with .innerHTML

Posted on 2008-06-09
5
1,090 Views
Last Modified: 2013-12-08
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.
0
Comment
Question by:Yo-NuTZ
  • 3
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 450 total points
ID: 21749492
If you do

<a href="javascript:someFunction()"

change it to

<a href="#" onClick="someFunction(); return false"
0
 

Author Comment

by:Yo-NuTZ
ID: 21749724
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)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21750137
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
0
 

Author Comment

by:Yo-NuTZ
ID: 21800474
i totally forgot, i'm very sorry, here are your points
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21800669
No problem.
Thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question