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 940293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:55:54+00:00 2026-05-15T21:55:54+00:00

For some reason the following code does not work as expected when in IE

  • 0

For some reason the following code does not work as expected when in IE 8, as noted in the comment. I’m trying to add a “writeSpecial” method to the document object, and this works fine the first time that the method is called, but whenever this is called a subsequent time, it becomes undefined.

However, this only happens in IE when I use the onload event. There seems to be no difference between an inline body onload and window.attachEvent(‘onload’, main);. If I call main() directly from the script block, it works fine. Again, this is only in IE.

Would anyone happen to know why this is?

Thanks!

<html>
  <head>
    <title>Test</title>
    <script type="text/javascript">

      document.writeSpecial = function(str)
      {      
        this.write(str + " [specialfied]");
      }          

      function main()
      {           
        alert(document.writeSpecial);
        document.writeSpecial('test 1');
        alert(document.writeSpecial);    //document.writeSpecial is undefined here in IE, works in firefox...why?
        document.writeSpecial('test 2');        
      }    
    </script>
  </head>
  <body onload="main()">
  </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-05-15T21:55:54+00:00Added an answer on May 15, 2026 at 9:55 pm

    I did some testing and as near as I can figure in IE document.write resets the document object. So here is a revised version that will work. If you didn’t use the write function I don’t think you would have had any trouble. Maybe someone else can elaborate on why IE does this.

    window.onload=function(){
    function foo(str){
      document.write(str + " [specialfied]");
      document.writeSpecial=foo;
    }
    document.writeSpecial=foo;
    main();
    function main(){
      document.writeSpecial('test 1');
      document.writeSpecial('test 2');        
    }};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First of all, it's a really bad idea to use… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer If you are not dead set on using a listbox,… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer killproc will terminate programs in the process list which match… May 16, 2026 at 9:17 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following code, which is the basis for pagination in a larger
OK, I have an Apple-themed nav bar, and for some reason there is some
OK, I'm trying to include some animating backgrounds using Spritely as a test on
I'm trying to follow the custom module tutorial at http://dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/modules-and-namespaces/creating-your-own-modul I've got a local
I'm trying to learn jQuery and it occurred to me that existing JS in
I am creating a chunk of HTML/JavaScript with the below code: $result = mysql_query(SELECT
I am trying to create a link to destroy and entry in the DB
I am trying to make a navigation that uses simple unordered lists to list
The following are the two ways of initializing a char array: char charArray1[] =
I'm trying to write a jQuery script (I have never written one before and

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.