I write 2 file .htm like:
===1.htm===
<iframe src=“2.htm” id=“ifm”></iframe>
<script>
function n()
{
y=ifm.document.getElementById(“myHeader”);
alert(y.innerHTML);
}
</script>
<input type=“button” value=“button2” onclick=“n();” />
===2.htm===
<a id=“myHeader” src=“#”>Thu the </a>
======================================
Resul : when I run 1.htm by IE, and I click "Button 2 ", will show alert “Thu the”.
I want to get text “thu the”, with file 2.htm is file online like: “http://muangay123.com/2.htm” .
HELP ME!
Thanks All !!
In the function you’ve written, you’re using a variable “ifm” that is undefined. You’re also polluting the global scope - you should really be using var
to declare variables. That’s part of the problem. The other part is that you can only access the contents of iframes via a special contentWindow object:
function n() {
var y = document.getElementByID('ifm').contentWindow.document.getElementById("myHeader");
alert(y.innerHTML);
}
In the future, please use syntax highlighting for your code.
Thanks u,
I tried it again, but the your fucntion don’t run .
I want to get “Thu the” from http://muangay123.com/2.htm
Like:
<iframe src=“http://muangay123.com/2.htm” id=“ifm”></iframe>
<script>
function n()
{
var y=ifm.document.getElementById(“myHeader”);
alert(y.innerHTML);
}
</script>
<input type=“button” value=“button2” onclick=“n();” />
===http://muangay123.com/2.htm===
<a id=“myHeader” src=“#”>Thu the </a>
But the function don’t run . This function run only when I run it is offline . Hix
The two have to be on the same domain for JavaScript to be able to communicate between them.