Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8068093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:32:42+00:00 2026-06-05T12:32:42+00:00

Each time I load a page in Internet Explorer 7 or greater I get

  • 0

Each time I load a page in Internet Explorer 7 or greater I get the error Object Expected when calling the function below. The script appears right at the bottom of the page before the closing </body> tag. There are no elements with the same name or id.

<script type="text/javascript">
     window.onload = show();
</script>

The Javascript function it is attempting to call is

function show() {
    obj1
     = document.getElementById("container").innerHTML
     = '<div style="width: 960px; height: 2000px;"><p>Hello World.<br>Here I am.</p>'
         + '<p><a href="#" onclick="hide();">test</a></p></div>';
}
  1. Why does this error not appear in any of the other browsers?
  2. What do I need to change to resolve the issue?

EDIT 0

If I move the function show into the same block at window.onload, hide() now no longer works.

Javascript code

function show() {
    obj1
     = document.getElementById("container").innerHTML
     = '<div style="width: 960px; height: 2000px;"><p>Hello World.<br>Here I am.</p>'
         + '<p><a href="#" onclick="hide();">test</a></p></div>';
}

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

HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict/EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtm1-strict.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" />
    <meta http-equiv="content-language" content="en-us" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="author" content="" />
    <meta name="copyright" content="&copy; 2012" />

    <title>takeover</title>

    <base href="" />
    <link rel="stylesheet" href="" />

    <style type="text/css" media="all" />

    #container {
         position:absolute;
         text-align:center;
         background-color:#fff;
         z-index:9999;
    }

    </style>

    <script type="text/javascript" src="takeover.js"></script>
</head>
<body>
    <div>
        <div id="container"></div>
        <p><a href="#">qwe</a></p>
    </div>

<script type="text/javascript">
     window.onload = show;
</script>
</body>
</html>

EDIT 1

Message that appears when using non-Internet Explorer browsers when placing alert(show) before window.onload

enter image description here

EDIT 2

The message displayed after removing all the white spaces. Again this only works in non-Internet Explorer browsers.

enter image description here

EDIT 3

Tried window.show = function show() and window.hide = function hide() however still get an error in Internet Explorer. The error is show as below.

enter image description here

EDIT 4

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 show is undefined.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict/EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtm1-strict.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" />
    <meta http-equiv="content-language" content="en-us" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="author" content="" />
    <meta name="copyright" content="&copy; 2012" />

    <title>takeover</title>

    <base href="" />
    <link rel="stylesheet" href="" />

    <style type="text/css" media="all" />

    #container {
         position:absolute;
         text-align:center;
         background-color:#fff;
         z-index:9999;
    }

    </style>


</head>
<body>
    <div>
        <div id="container"></div>
        <p><a href="#">qwe</a></p>
    </div>

<script type="text/javascript">
    alert(show)
    window.show = function show() {
obj1 = document.getElementById("container").innerHTML =  '<div style="width: 960px; height: 2000px;"><p>Hello World.<br>Here I am.</p><p><a href="#" onclick="hide();">test</a></p></div>';
}

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;
</script>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:32:45+00:00Added an answer on June 5, 2026 at 12:32 pm

    This line…

    window.onload = show();
    

    Should be this…

    window.onload = show;
    

    …because you need to assign the show function itself to window.onload, not its return value from calling it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have single php dynamic page that load image each time app user is
I have a list of images. When the page load each time I want
I load content via jQuery load() but for each time I load a given
Each time I add in the correct code, it gives me the same error
Each time I click the Run as button, I get the following message. The
Every time I load a new page with UIWebView the before loaded page is
$(#News-Pagination).pagination(122, { items_per_page:20, callback:handlePaginationClick }); Using this, but on page load handlePaginationClick callback function
We are trying to improve the page load time of a site. In addition
I Have Javascript Function and I Want to call it On each time user
Each time my webpage is loaded it runs a routine in the page_load event

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.