Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

onbeforeunload event triggered unnecesarily when writing into div with .innerHTML

Posted on 2008-06-09
5
Medium Priority
?
1,105 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
Suggested Courses

604 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