Solved

onbeforeunload event triggered unnecesarily when writing into div with .innerHTML

Posted on 2008-06-09
5
1,083 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now