a javascript makes blank screen in IE but works in FF and Chrome

Dear experts,

I have a function which called at <body onload="setNavColumnHeight()">

    function setNavColumnHeight(){
      var height = Math.max(document.getElementById("mainNavColumn").offsetHeight, document.getElementById("bodyContainer").offsetHeight);
      document.getElementById("mainNavColumn").style.height = height + "px";
    }

Everything was fine before I add this call in onload. My page displays correctly on IE,FF,Chrome. However, IE gave me a blank screen after I added this into onload while other browsers displays correctly. In fact in IE, I can see the page for a very short moment and then I tried alert and the calculated height is correct.

Any ideas?
candychan611Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dhiraj MuthaLevel DCommented:
Can you try the same code on any other system and have a check.
0
jitendrajlsCommented:


Generally these type of problem occured with IE (time out problem on onload time)

add a setTimeout function to solve this problem..........................

function firstCallOnbodyLoad()
{
 setTimeout("setNavColumnHeight()",1000);
}

<body onload=" firstCallOnbodyLoad()">

    function setNavColumnHeight(){
      var height = Math.max(document.getElementById("mainNavColumn").offsetHeight, document.getElementById("bodyContainer").offsetHeight);
      document.getElementById("mainNavColumn").style.height = height + "px";
    }
0
candychan611Author Commented:
I have do more test on this and let me describe it more clearly.

This function is in a page which will be loaded into an iframe. While I execute this function via <body onload="setNavColumnHeight()">. It makes the content in the iframe blank and REAPPEAR if I resize the IE window. I've tested it by IETester and DebugBar, no error message. If I load this page in IE directly, no error too.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

candychan611Author Commented:
Dear jitendrajls,

Isn't the onload event fires when the page finish loading? Why there is still a timeout? And this function is so simple it should not execute long enough to make it timeout either.

I've tried your code. set timeout to 1 second make the content to display 1 second before disappear. Strange.

Also please see my last reply. I found it maybe some kind of iframe problem.

Thanks a lot!

IE gives me a lot of headache. Points raised for someone who can help me out :)
0
Michel PlungjanIT ExpertCommented:
try this

 function setNavColumnHeight(){
var height = Math.max(document.getElementById("mainNavColumn").offsetHeight, document.getElementById("bodyContainer").offsetHeight);
  if (height > 100) document.getElementById("mainNavColumn").style.height = height + "px";
else alert('Height is only:' height); // remove this line when you have seen that IE does not do what you thought it would
}

My guess is that IE has not set the heights at the time you execute
0
candychan611Author Commented:
Dear mplungjan,

Seems there's a typo in alert('Height is only:' + height); ?? But this alert never comes out in IE. So I guess the situation is came from the combination of all my functions in the page. Let me go back to create some test pages and try to isolate the problematic code more.
0
Michel PlungjanIT ExpertCommented:
Yes, sorry about the missing plus
0
candychan611Author Commented:
Dear mplungjan,

I have isolated the problematic code and it turns out to be a css problem! Here I show you the code to reproduce this problem.

The parent page,
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
  <link href="test-styles.css" rel="stylesheet" type="text/css" />
</head>

<body>
  <iframe id="template" src="test-iframe.html" height="600px" width="100%"></iframe>
</body>
</html>

The page in iframe,
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
  <link href="test-styles.css" rel="stylesheet" type="text/css" />
  <script language="JavaScript">
    function setNavColumnHeight(){
      var height = Math.max(document.getElementById("mainNavColumn").offsetHeight, document.getElementById("bodyContainer").offsetHeight);
      document.getElementById("mainNavColumn").style.height = height + "px";
    }
  </script>
</head>

<body onload="setNavColumnHeight();">
  <div id="topContainer">
    <div id="mainNavColumn" class="navColumn">abc</div>
    <div id="bodyContainer">def</div>
  </div>
</body>
</html>

And the css,
* {
    position:relative;
    margin:0px 0px 0px 0px;
    padding:0px 0px 0px 0px;
   }
html,body{
    width:100%;
    height:100%; /* we need both html and body to have this in order for their child elem's 100% setting to work in FF!! */
    }
body {
    text-align:center; /* replace center tag, for IE */
    font-family:Arial;
    font-size:12px;
    color:#404040;
    background-color:#FFFFFF;
    }
iframe {
    border:0px;
    display:block;
    }

#topContainer {
    text-align:left;
    margin:0px auto 0px auto; /* replace center tag, for other browsers */
    width:800px;
    }

.navColumn {
    float:left;
    width:130px;
    border:solid 1px red;
   }

#bodyContainer {
    float:left;
    width:668px;
    border:solid 1px black;
    }

In fact, the page can be displayed if I delete its link to the css file. Furthermore, #topContainer / .navColumn / #bodyContainer have no effect to the problem. You can just delete it. I leave them here for you to see the divs easier only.
0
Michel PlungjanIT ExpertCommented:
So you are fine?
0
candychan611Author Commented:
Dear mplungjan,

Of course not. These code can only re-produce the problem. However, I don't see any errors in my css with my limited knowledge. :-(
0
Michel PlungjanIT ExpertCommented:
remove the position relative on all items

Then it works
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
candychan611Author Commented:
Thank you mplungjan! It works! I will allocate the points to you! Could you tell me the reason too?
0
Michel PlungjanIT ExpertCommented:
No, but I bet someone else can ;)

http://www.google.com/search?q=ie+position+relative+bug

There used to be a Peek-a-boo bug in IE6 but this is a newer bug, I had it in IE7 on XP
0
candychan611Author Commented:
Your are most helpful sir! Thanks again for your help! :) BTW, why do I get into IE bugs everyday? -_-"
0
Michel PlungjanIT ExpertCommented:
You get bugs when you push the limits of the browser.
0
candychan611Author Commented:
Well....This is just my first time to build a website! A relatively static site with just 3x pages on a static web space (Rare in this century). I guess IE bugs are just too many! :-( A pity it's my company's website, otherwise I will just declare it as "Firefox & Chrome" only ;-)
0
Michel PlungjanIT ExpertCommented:
What I meant was that if you add many scripts or do many things out of the ordinary, you hit issues. For example why have an iframe at all if you resize it to content anyway?
It makes the page do two http requests and has possible issues.
0
candychan611Author Commented:
It's because I want to simulate the "master page" function for a ***totally static web space***. I think I can only do it javascript (client side), with my limited knowledge. For the server side javascript, I need to check company's old email record with the provider first.

I am now adding a invisible box to the template to hold a calculated "real" height of my page and resize the iframe by that. adding height 100% will cause the display of double scrollbar for IE all times and Firefox sometimes.

I hope the new Xframe comes faster!

BTW, for "doing things out of the ordinary", using iframe to load other page inside a page seems oldest way to get task done (for me). ^__^"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Browsers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.