0

So I have this nice piece of javascript that will load local HTML files into my document for me on the fly, which is pretty cool.

function load_html(src) {

   var html = document.createElement("object");
   html.type = "text/html";
   html.data = src;

   document.getElementById("wrapper").appendChild(html);

}

I got the idea from the post here How do I load an HTML page in a <div> using JavaScript?.

The only problem with it is that it seems that the object tag that I create needs a default width and height, which I want it to wrap the size of it's containing elements, and the new elements that are within the object tag have their own set of css values instead of using the css value of the current page.

Does anyone know how to make the elements within my object get the css values from my current page?

Also, how can I make my object be the size of it's containing elements?

I'm sure there is an easy way to do it, but I haven't found much on object tags.

Community
  • 1
  • 1
nyduss
  • 137
  • 2
  • 13
  • 1
    To make the elements inside `#wrapper` to use the current page's css, I would suggest you use something like jquery's `$.load()` method instead. You can use it like `$( "#wrapper" ).load( src );` With your current approach, `object` is acting like an `iframe` hence it need to load your parent page's css to apply it to the objects inside it. – DigitalDouble May 08 '15 at 02:43
  • Yeah, I was trying to avoid the use of JQuery, but I've been seeing it used more and more for loading HTML into an element... so I might just end up doing it. – nyduss May 08 '15 at 02:47
  • So using the $.load() method worked pretty well, although it just 'rewrote' everything within the #wrapper element... I would like it to append to the bottom of the element if at all possible. – nyduss May 08 '15 at 03:31
  • 1
    Here's a similar thread that addresses your concern regarding appending instead of replacing: http://stackoverflow.com/questions/3999807/can-jquery-load-append-instead-of-replace – DigitalDouble May 08 '15 at 03:43

0 Answers0