YAPS: IE 6, body onload, 'n U

by Lisa Nicholls Sun, May 18 2008 20:37

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?

Tags:

ASP.NET | YAPS

Comments (30) -

9/1/2009 4:02:23 AM #

computer terms

What a great post, i like it so much.

computer terms United States

9/1/2009 11:13:05 AM #

wines

great post and thanks for the information.

wines Turkey

9/4/2009 7:45:42 AM #

glipmax

What a great discussion, i love it.

glipmax United States

9/8/2009 7:11:16 AM #

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 United States

1/26/2010 10:43:21 PM #

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 Singapore

2/10/2010 8:32:11 PM #

disco rigido

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

thanks for sharing

disco rigido United Kingdom

2/26/2010 1:26:17 PM #

online term paper

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

online term paper Puerto Rico

3/3/2010 4:04:52 AM #

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 United States

3/12/2010 8:20:24 PM #

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 United States

3/16/2010 5:42:49 PM #

homes for sale in queen creek az

very entertaining blog..keep it up..

homes for sale in queen creek az United States

4/22/2010 7:45:30 PM #

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 United States

5/19/2010 2:18:22 AM #

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 Iceland

8/16/2010 3:32:34 PM #

Edwin

Sure is weird. IE6 gives me headaches all the time and I can't count the times I wished there was just one uniform browser that worled 100% of the time Smile

Edwin Netherlands

9/2/2010 2:55:43 AM #

massage school utah

Really a good blog and some tips too fantastic.

massage school utah United States

9/3/2010 4:38:45 AM #

career coach certification

Great post. Here I learn something new things about IE6. Moreover coding of master page is also great. I want to know the coding of master page. Thanks for the post.

career coach certification United States

9/4/2010 2:40:51 PM #

luxury watch reviews

Nice post!

luxury watch reviews United States

9/10/2010 1:46:02 AM #

compare online dvd rental

Quite useful information for me...thanks

compare online dvd rental United States

9/20/2010 3:09:21 AM #

onketing india

Thanks for the code...really helped me in my project...

onketing india United States

9/22/2010 11:36:12 PM #

car classifieds

Thanks for this information.I am always in search of these tips

car classifieds United States

9/23/2010 12:17:11 AM #

fulfillment services

Thanks for such article....The code helped me a lot...keep posting more...

fulfillment services United States

10/5/2010 11:27:02 PM #

Flowers magazine

I wonder how you got so good.  This is really a fascinating blog, lots of stuff that I can get into.  One thing I just want to say is that your Blog is so perfect!

Flowers magazine United States

10/12/2010 12:59:22 AM #

buying a new car

How about for Chrome? Isn't it applicable for Google Chrome?

buying a new car United States

11/2/2010 10:04:38 PM #

Security Printing

I like your blog name"YAPS". You give very good information about Java script and coding. You have good knowledge about IT field which is very good thing. Keep it up!

Security Printing United States

11/3/2010 3:51:59 PM #

Torqeedo electric motor

great site full of great info

Torqeedo electric motor United States

11/5/2010 6:30:52 PM #

radley bags

How sure you are that this will run successfully? I just tested it on my system and failed. Did I missed something here?

radley bags United States

11/13/2010 1:20:20 AM #

reno massage

This script is very interesting keep it up

reno massage United States

11/26/2010 4:53:36 AM #

van for sale

Its quite frustrating having so many different browsers that all require a slightly different code to get them to work the way you want.

van for sale United Kingdom

9/12/2011 9:18:05 AM #

Denise

This is still pretty confusing to me. I usually use Firefox but of course would want my visitors on ie to not have any problems. I guess I am a fairly new blogger so I am still learning. Thanks for this tip!

Denise United States

10/25/2011 6:20:03 AM #

madeira vakantie

hej this is a really good poast! thanks for this I've learned something and have one problem it can solve keep it

madeira vakantie Netherlands

11/19/2011 11:32:31 AM #

Sandra Martin

Very nice! Smile

Sandra Martin Sweden

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading