?
Solved

onbeforeunload event triggered unnecesarily when writing into div with .innerHTML

Posted on 2008-06-09
5
Medium Priority
?
1,103 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 1800 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

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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…
Suggested Courses

770 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