Is there a way to create a DOM document object to hold the contents of
an external html?
I have two pages:
content.html contains some content.
index.html would like to access the contents of a particular <div> with
an id of "important" within content.html.
how would I do this? I know I can hack around and load the
content.html in an iframe embedded in index.html. Then, I can make the
iframe not visible. But, If theres a better way to do this (an easier
way), I'd much rather take that approach.
Vince
jshanman - 28 Apr 2006 20:13 GMT
> Is there a way to create a DOM document object to hold the contents of
> an external html?
[quoted text clipped - 10 lines]
>
> Vince
If content.html is valid xhtml(xml), then you could parse the document
like an xml file.
http://www.google.com/search?q=javascript+parse+xml
The other alternitive is to have a server page parse the document and
return the content you want. You could do this dynamicly using the
XmlHttpRequest object, or even simpler using
var s = document.createElement("script");
s.src = "http://www.u.com/getpage.php?u=<url>&d=<id of div>";
the getpage file could open the resource in $u and search for a div
with an id of $d
- JS
Martin Honnen - 29 Apr 2006 12:59 GMT
> how would I do this? I know I can hack around and load the
> content.html in an iframe embedded in index.html. Then, I can make the
> iframe not visible. But, If theres a better way to do this (an easier
> way), I'd much rather take that approach.
Use the iframe, there are no pure in memory text/html DOM
implementations currently in browsers that would allow loading from a URL.
Iframes on the other hand are quite well supported.

Signature
Martin Honnen
http://JavaScript.FAQTs.com/