IE method:
document.frames ['myframe']. Document.GetelementByid ('test'). Value;
Firefox method:
document.GetelementByid ('MyFrame'). Contentwindow.document.GetelementByid ('test'). Value; Value;
IE, Firefox method:
Copy code code as follows:
function getValue () {
var tmp = '';
if (document.frames) {
TMP += 'IE said:';
tmp += document.frames ['myframe']. Document.GetelementByid ('Test'). Value;
} Else {
tmp = document.GetelementByid ('myframe'). Contentwindow.document.GetelementByid ('test'). Value;
}
alert (tmp);
}
Example code:
The code in the A.html page
Copy code code as follows:
<html>
<head>
<meta http-equiv = "content-type" content = "text/html; charset = utf-8">
<Title>
JavaScript Get the value test of the element in the page in iframe
</Title>
</head>
<body>
<iframe id = "myframe" src = 'b.html'> </iframe>
<input type = "Button" id = "btn" onClick = "GetValue ()" Value = "Test">
<script type = "text/javascript">
function getValue () {
var tmp = '';
if (document.frames) {
TMP += 'IE said:';
tmp += document.frames ['myframe']. Document.GetelementByid ('Test'). Value;
} Else {
tmp = document.GetelementByid ('myframe'). Contentwindow.document.GetelementByid ('test'). Value;
}
alert (tmp);
}
</script>
</body>
</html>
Code in B.html page
Copy code code as follows:
<html>
<head>
<meta http-equiv = "content-type" content = "text/html; charset = utf-8">
<Title>
I am a page in iframe
</Title>
</head>
<body>
<input type = 'text' id = "test" value = 'Welcome to visit: justFlyHigh.com'>
</body>
</html>