Access to the external content of the HTML page of objects

I was looking for the answer to this question, but I can’t figure out how to do it.

I want to access the contents 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 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>

Not a single warning gives me the message "This is an included page", is there a way to get this content from the DOM?

EDIT: Window [0] .document.getElementById ("includedDiv") firstChild.nodeValue. was a good response to access through the DOM, the object tag simply creates another window :) http://www.w3schools.com/jsref/prop_win_length.asp

+3
source share
3 answers

Even better answer: you can access the contents of the object tag via the DOM, this is just another window!

window[0].document.getElementById("includedDiv").firstChild.nodeValue;

: D http://www.w3schools.com/jsref/prop_win_length.asp

0

document.getElementById('id').innerHTML document.getElementById('id').outerHTML , ...

. innerHTML

0

Got! Just use

window.parent.mainPageMethod(document.getElementById("includedDiv").firstChild.nodeValue);

on the included page, and you can get the contents of the div in the Javascript function from the main page!

Thanks for trying to help Jay, I have to admit that when you talked about the window.name property, it set me in the right direction :)

0
source

All Articles