title: Internet Explorer 7+ returns the error "Object expected" although none of the other browsers do
body: <p>Each time I load a page in Internet Explorer 7 or greater I get the error <code>Object Expected</code> when calling the function below. The script appears right at the bottom of the page before the closing <code>&lt;/body&gt;</code> tag. There are no elements with the same <code>name</code> or <code>id</code>.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
       window.onload = show();
  &lt;/script&gt;
  </code></pre>
  
  <p>The Javascript function it is attempting to call is</p>
  
  <pre><code>function show() {
      obj1
       = document.getElementById("container").innerHTML
       = '&lt;div style="width: 960px; height: 2000px;"&gt;&lt;p&gt;Hello World.&lt;br&gt;Here I am.&lt;/p&gt;'
           + '&lt;p&gt;&lt;a href="#" onclick="hide();"&gt;test&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;';
  }
  </code></pre>
  
  <ol>
  <li>Why does this error not appear in any of the other browsers?</li>
  <li>What do I need to change to resolve the issue?</li>
  </ol>
  
  <p><strong>EDIT 0</strong></p>
  
  <p>If I move the function <code>show</code> into the same block at <code>window.onload</code>, <code>hide()</code> now no longer works.</p>
  
  <p>Javascript code</p>
  
  <pre><code>function show() {
      obj1
       = document.getElementById("container").innerHTML
       = '&lt;div style="width: 960px; height: 2000px;"&gt;&lt;p&gt;Hello World.&lt;br&gt;Here I am.&lt;/p&gt;'
           + '&lt;p&gt;&lt;a href="#" onclick="hide();"&gt;test&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;';
  }
  
  function hide() {   
      obj1 = document.getElementById("container");
      if(obj1){
          alert("Hi");
          obj1.style.display = "none";
          obj1.style.visibility = "hidden";
      }else{
          alert("Cannot find the element with id container.");
      }
  }
  </code></pre>
  
  <p>HTML code</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict/EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtm1-strict.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
      &lt;meta http-equiv="content-type" content="text/html; charset="UTF-8" /&gt;
      &lt;meta http-equiv="content-language" content="en-us" /&gt;
      &lt;meta name="keywords" content="" /&gt;
      &lt;meta name="description" content="" /&gt;
      &lt;meta name="author" content="" /&gt;
      &lt;meta name="copyright" content="&amp;copy; 2012" /&gt;
  
      &lt;title&gt;takeover&lt;/title&gt;
  
      &lt;base href="" /&gt;
      &lt;link rel="stylesheet" href="" /&gt;
  
      &lt;style type="text/css" media="all" /&gt;
  
      #container {
           position:absolute;
           text-align:center;
           background-color:#fff;
           z-index:9999;
      }
  
      &lt;/style&gt;
  
      &lt;script type="text/javascript" src="takeover.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt;
          &lt;div id="container"&gt;&lt;/div&gt;
          &lt;p&gt;&lt;a href="#"&gt;qwe&lt;/a&gt;&lt;/p&gt;
      &lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
       window.onload = show;
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>Message that appears when using non-Internet Explorer browsers when placing <code>alert(show)</code> before <code>window.onload</code></p>
  
  <p><img src="https://i.stack.imgur.com/Opaeh.png" alt="enter image description here"></p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>The message displayed after removing all the white spaces. Again this only works in non-Internet Explorer browsers.</p>
  
  <p><img src="https://i.stack.imgur.com/HjqDu.png" alt="enter image description here"></p>
  
  <p><strong>EDIT 3</strong></p>
  
  <p>Tried window.show = function show() and window.hide = function hide() however still get an error in Internet Explorer. The error is show as below.</p>
  
  <p><img src="https://i.stack.imgur.com/1ZN75.png" alt="enter image description here"></p>
  
  <p><strong>EDIT 4</strong></p>
  
  <p>Here is the updated code with all the functions in a single file. This does not work in any other browser and I get the error <code>show</code> is undefined.</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict/EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtm1-strict.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
      &lt;meta http-equiv="content-type" content="text/html; charset="UTF-8" /&gt;
      &lt;meta http-equiv="content-language" content="en-us" /&gt;
      &lt;meta name="keywords" content="" /&gt;
      &lt;meta name="description" content="" /&gt;
      &lt;meta name="author" content="" /&gt;
      &lt;meta name="copyright" content="&amp;copy; 2012" /&gt;
  
      &lt;title&gt;takeover&lt;/title&gt;
  
      &lt;base href="" /&gt;
      &lt;link rel="stylesheet" href="" /&gt;
  
      &lt;style type="text/css" media="all" /&gt;
  
      #container {
           position:absolute;
           text-align:center;
           background-color:#fff;
           z-index:9999;
      }
  
      &lt;/style&gt;
  
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt;
          &lt;div id="container"&gt;&lt;/div&gt;
          &lt;p&gt;&lt;a href="#"&gt;qwe&lt;/a&gt;&lt;/p&gt;
      &lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
      alert(show)
      window.show = function show() {
  obj1 = document.getElementById("container").innerHTML =  '&lt;div style="width: 960px; height: 2000px;"&gt;&lt;p&gt;Hello World.&lt;br&gt;Here I am.&lt;/p&gt;&lt;p&gt;&lt;a href="#" onclick="hide();"&gt;test&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;';
  }
  
  window.hide = function hide() { 
      obj1 = document.getElementById("container");
       if(obj1)
   {
     alert("Hi");
     obj1.style.display = "none";
     obj1.style.visibility = "hidden";
   }
   else
   {
     alert("Cannot find the element with id container.");
   }
  }
       window.onload = window.show;
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>