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

  • Home
  • SEARCH
  • 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 978255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:01:51+00:00 2026-05-16T04:01:51+00:00

When I try to get the contents of a htm file into a div

  • 0

When I try to get the contents of a htm file into a div using a xmlhttprequest object in Firefox it includes everything, but in IE it only includes the contents of the body tag. In other words it ignores all the styling (in the head tag) of the page, rendering it ugly.

Is it possible to get the full page when using xmlhttprequest in internet explorer?

edit:

document.getElementById('divtoreceivetheresponse').innerHTML = xmlHTTP.responseText

This line in FF gets the page contents including the <head></head> section.

In IE it just gets the contents inside the <body></body> section.

  • 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-16T04:01:52+00:00Added an answer on May 16, 2026 at 4:01 am

    I got an answer from elsewhere. Basically it does include all the page (not just the body) but IE chooses not to render it (probably the correct behavour)

    I therefore worked out some code to extract the css, place it in the head, and place the body stuff in the target div. So both html and css from the external page would be got.

    <html><head>
    <script type="text/javascript" language="javascript">
    function include(lyr,url)
    {
       if (document.all)
       {
          try {
          var xml = new ActiveXObject("Microsoft.XMLHTTP");
          xml.Open( "GET", url, false );
          xml.Send()
    
           }
          catch (e) {
          var xml = new ActiveXObject("MSXML2.XMLHTTP.4.0");
          xml.Open( "GET", url, false );
          xml.Send()
          }
       }
       else
       {
                var xml=new XMLHttpRequest();
                xml.open("GET",url,false);
                xml.send(null);
       }
    
       text = xml.responseText;
       text = text.replace("<html>","");
       text = text.replace("</html>","");
       text = text.replace("<head>","");
       text = text.replace("</head>","");
       text = text.replace("<body>","");
       text = text.replace("</body>","");
       splittext = text.split("<style type=\"text/css\">");
       splittext = splittext[1].split("</style>");
       css = splittext[0];
       everythingelse = splittext[1];
    
       addCss(css);
       document.getElementById(lyr).innerHTML=everythingelse;   
    
    }
    
    function addCss(cssCode) {
    var styleElement = document.createElement("style");
      styleElement.type = "text/css";
      if (styleElement.styleSheet) {
        styleElement.styleSheet.cssText = cssCode;
      } else {
        styleElement.appendChild(document.createTextNode(cssCode));
      }
      document.getElementsByTagName("head")[0].appendChild(styleElement);
    }
    
    
    </script>
    </head>
    <body onload="include('adiv','test.htm')">
    <div id="adiv">sdfgboui hsdguhwruh o ikuy </div>
    </body>
    </html>
    

    The code is far from perfect, but it does the job and I will probably improve the code bit by bit now that I know it works

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

Sidebar

Related Questions

i try to get my FragmentPagerAdapter working, but the examples are a bit to
I try to get the main window handle using following code in Lazarus (Free
I try to get the last modification date of a file: NSFileManager *fm =
I try to get this following url using the downloadURL function as follows: http://www.ncbi.nlm.nih.gov/nuccore/27884304
I am try to get a URL from a one server and using that
I try to use the code as below to get the website htm source
I have tried many methods to try and get the contents of a url,
I try to the get source of a page using file_get_contents() via proxy using
I am using this code to try to get json data from many json
Hi i'm trying to get the content from a json file, but i can't

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.