Tykhon
04-29-2003, 12:26 PM
This should be simple, I made an IFRAME (with a src) and I want to assing the HTML-code inside the IFRAME to a variable, when I do this (using innerHTML), the variable always seems to be empty.
|
Click to See Complete Forum and Search --> : assing the HTML-code of an IFRAME to a variable Tykhon 04-29-2003, 12:26 PM This should be simple, I made an IFRAME (with a src) and I want to assing the HTML-code inside the IFRAME to a variable, when I do this (using innerHTML), the variable always seems to be empty. Jona 04-29-2003, 12:35 PM var myVar = top.frames['IFRAMEName'].innerHTML Jona 04-29-2003, 12:36 PM Also, this might help: http://www.geocities.com/god_loves_07/writetoiframe.html Tykhon 04-29-2003, 12:38 PM now it says : "undefined". Do you know what that means? Jona 04-29-2003, 12:40 PM Try this: parent.frameName.innerHTML Tykhon 04-29-2003, 12:45 PM again undefined, here's my code: <HTML> <HEAD> <TITLE> Garden of Fertility </TITLE> <SCRIPT> <!-- function interactive() { var gu = parent.guest.innerHTML; alert(gu); } --> </SCRIPT> </HEAD> <BODY bgcolor="#FFFFFF"> <iframe id="guest" name="guest" src="http://server.scripthost.com/guestbook?tykhon" onload='interactive();'></iframe> </BODY> </HTML> Jona 04-29-2003, 12:49 PM If you take off the innerHTML part, it returns "[object]." So it's probably because (1) it's on a different server, or (2) it's a PHP file. Jona 04-29-2003, 12:51 PM As a matter of fact, the code works on my local server, but when I link to other servers, it does not. The page loads, and the innerHTML returns undefined. I believe this is because it is cross-server. Tykhon 04-29-2003, 12:53 PM it's on a different server, that's true and it could be php (although I don't think so) but, when I use a html-file that's on my server I also get the alert: undefined ... Jona 04-29-2003, 12:56 PM OK, here's what you do. Put the whole HTML file in a DIV. Then use parent.guest.myDiv.innerHTML Tykhon 04-29-2003, 01:00 PM I can't, the page that's loaded in the iframe isn't mine, I can't change anything, I just want to get the HTML-code of a webpage so I can use it as a variable... Is that possible? Jona 04-29-2003, 01:03 PM Well, you can't get the innerHTML of an entire page unless you try setting something like this (http://geocities.com/god_loves_07/viewsource.html) to a variable (which is probably impossible). If you can't change the file or don't have access to it, then you might want to use a server side language to pull the source. Other than that, I don't think it's possible.. Tykhon 04-29-2003, 01:16 PM I agree, that's probably impossible and I have thought about using ssi, but I don't think my server alows using that language Tykhon 04-29-2003, 01:26 PM other question, is it possible to extract the text and not the HTML-code by using javascript? Jona 04-29-2003, 01:41 PM Neither innerText nor innerHTML work. I even tried text, but it doesn't have any attributes. You can try parent.guest.document.body.innerHTML Tykhon 04-29-2003, 01:49 PM doesn't work either, so I assume it's impossible to get text from another page that's not on the same server, thanks a lot for all your help, i'll have to find another way... webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |