TechSpoken
"Any ideas?" is the most frequently-asked question in technical forums. My answer is: yes.

YAPS: IE 6, body onload, 'n U

May 18, 2008 19:37 by LSN

I've decided I should have a blog category called "YAPS" (Yet Another PostScript), for all the times when I post and then think of something more I want to say to clarify on the subject later. This one clarifies http://www.spacefold.com/lisa/post/Anchors-Aweigh%2c-Away.aspx.

It turns out that under some very specific circumstances IE 6 isn't calling the body onload function, which is the logical place to put the navCheck function I discussed in that blog post.  It's not due to anything specific in my javascript; you can see the same behavior with anything in the body onload, for any page on which this occurs.

It actually works fine on Spacefold Articles, even in IE 6. So I suspect seeing the issue requires having a code-behind page, in your master page (because the SpacefoldArticles.Master file doesn't).  It might also require having a Page_Load function in that code-behind page.  Maybe ASP.NET handling either pre-empts the onload, or doesn't piggyback on it correctly from IE 6's POV, or just does something else in the wrong sequence, in this situation. 

Oh wait -- it may depend on your current DOCTYPE, too, because IE 6 is finicky about what it does and how it complies with standards (or doesn't) depending on DOCTYPE.  My DOCTYPE declaration for the "problem page" happens to be:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Whatever.  I've seen a lot of people point to mysterious failures of body onload in IE 6.  Here is an example.  There's a broad range of descriptions and observations of the failures.  Just type "body onload ie 6" in the search engine of your choice, and you'll doubtless see.

So here's my resolution: take the javascript out of the onload call, just don't use that event. Rather than getting fancy with adding events or figuring out whatever messiness the ASP.NET sequence is causing "behind the scenes"...  call the same script after all relevant elements in the page have been rendered, directly in the body of the page. 

In my case, that means that the master page finishes up like this:

<!-- more here -->
<asp:ContentPlaceHolder ID="MainContentArea" runat="server">
 </asp:ContentPlaceHolder>
 </div>
  <!-- Bottom Information Area -->
  <div id="BottomArea">
   yadayadayada
     </div>  
</form>
<!-- run the script after all the elements are defined -->
<script>
   navCheck();
</script> 
</body>
</html>

If you're not trying to access items on the page, you can probably put it somewhere more intuitive in the body, but (as you may remember from the original post), the navCheck() function is going to try to find an element on the page, using document.getElementById, and jump to that element if it's found.  So all the page elements have to be prepared and available, before this script actually runs.

Is that better than a plan?

Seems to work... in FireFox, Opera, IE, and Safari.

Weird, huh?



Categories: ASP.NET | YAPS
Actions: E-mail | Permalink | Comments (18) | Comment RSSRSS comment feed

Comments

September 1. 2009 03:02

computer terms

What a great post, i like it so much.

computer terms

September 1. 2009 10:13

wines

great post and thanks for the information.

wines

September 4. 2009 06:45

glipmax

What a great discussion, i love it.

glipmax

September 8. 2009 06:11

Ear Defenders

I admire the valuable information you offer in your articles. I will bookmark your blog and have my children check up here often. I am quite sure they will learn lots of new stuff here than anybody else!

Ear Defenders

January 26. 2010 21:43

diamond cluster ring

This is my first time i visit here. I found so many interesting stuff in your blog, especially its discussion. From the tons of comments on your posts, I guess I am not the only one having all the leisure here! Keep up the excellent work.

diamond cluster ring

February 10. 2010 19:32

disco rigido

taking the javascript out of the onload call was a brilliant move... Smile

thanks for sharing

disco rigido

February 26. 2010 12:26

online term paper

It's great to read your post all the time..thanks for sharing such a great information

online term paper

March 3. 2010 03:04

Genworth Life and Annuity

I admire your work and effort you have done here. Your  blog category called "YAPS is great. Thanks for the post.

Genworth Life and Annuity

March 12. 2010 19:20

Watch Pacquiao Vs Clottey Live online

nice blog i learn a lot from it.
Thanks for sharing.

regards,

rosela

Watch Pacquiao Vs Clottey Live online

March 16. 2010 16:42

homes for sale in queen creek az

very entertaining blog..keep it up..

homes for sale in queen creek az

April 22. 2010 18:45

rap instrumentals

Like others, I often got failed when trying to onload page on IE. Hopefully, this will help me fix my problem.  

rap instrumentals

May 19. 2010 01:18

regles des jeux au casino

I am sure the same concept can be used in a varity of way to get lot of real time information.The person who create this post he is a great human..thanks for shared this with us.

regles des jeux au casino

Add comment


(Will show your Gravatar icon)

  Country flag

Click to change captcha

biuquote
  • Comment
  • Preview
Loading