Click to See Complete Forum and Search --> : Showing HTML from another page in innerHTML


mnharshavardhan
April 20th, 2002, 02:39 AM
Hi,

How do I access HTML code of another page to be
shown in a DIV's innerHTML ? All the examples I
find just seem assign the HTML to be shown in the
DIV tag to the innerHTML property, like...

document.My_Div_Tag.innerHTML = "<P>Hi</P>"

But I want to have the "<P>Hi</P>" in another
HTML page so I can reuse it & do like...

document.My_Div_Tag.innerHTML = source_of("P.htm");

Is there a way in Javascript to access code of a
specified HTML page this way ?

Thanx a lot.

websmith99
September 27th, 2002, 04:09 PM
Do you have control over the code in the other page (P.htm) ?

If so, here's a trick you can do:

1. Load "P.htm" into another hidden frame.
2. Have "P.htm" read it's own HTML using innerHTML and assign to a variable.
3. Have your document in the main frame read the value of that variable in the hidden frame, then assign it to the innerHTML.

Note: to be sure there is no race condition (the hidden frame not loaded yet when you try to access the variable defined there) first check to see if the hidden frame is fully loaded. You can put this on a setInterval() method.