Access external HTML page content of object tags
10,065
Even better answer: you CAN access object tag content through the DOM, it is just another window!
window[0].document.getElementById("includedDiv").firstChild.nodeValue;
That's it :D http://www.w3schools.com/jsref/prop_win_length.asp
Comments
-
baptx almost 2 years
I've searched an answer to this question but can't get a way how to do it.
I want to access the content of a div that I have included in an object tag.
My include.htm file:
<div id="includedDiv">This is the included page</div>
What I have tried :
<html> <head> <title>Get element from object included page</title> </head> <body> <p>Test: This is the main page</p> <object id="obj" data="include.htm"></object> <script> //alert(document.getElementById("includedDiv").firstChild.nodeValue); //alert((document.getElementById("obj")).document.getElementById("includedDiv").firstChild.nodeValue); alert(document.getElementById("obj")["includedDiv"]); </script> </body> </html>
None of the alert prints me the message "This is the included page", is there a way to get this content from the DOM?
EDIT: window[0].document.getElementById("includedDiv").firstChild.nodeValue; was the the good answer for access through the DOM, object tag just creates another window :) http://www.w3schools.com/jsref/prop_win_length.asp