We help IT Professionals succeed at work.

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

735 Views
Last Modified: 2013-12-08
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?
Comment
Watch Question

Dhiraj MuthaLevel D

Commented:
Can you try the same code on any other system and have a check.


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";
    }

Author

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.

Author

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 :)
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
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

Author

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.
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
Yes, sorry about the missing plus

Author

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.
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
So you are fine?

Author

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. :-(
IT Expert
CERTIFIED EXPERT
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you mplungjan! It works! I will allocate the points to you! Could you tell me the reason too?
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
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

Author

Commented:
Your are most helpful sir! Thanks again for your help! :) BTW, why do I get into IE bugs everyday? -_-"
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
You get bugs when you push the limits of the browser.

Author

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 ;-)
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
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.

Author

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). ^__^"
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.