Home > Article > Web Front-end > js method to implement iframe frame value (compatible with IE, firefox, chrome, etc.)_javascript skills
The example in this article describes the method of realizing iframe frame value in js. Share it with everyone for your reference, the details are as follows:
Why are there so many different browsers in the world? Every time I encounter browser compatibility issues with js/css, I always sigh like this. I really hope that all these browser companies will fall and only one will remain (obviously this is an impossible wish) , let’s get back to the point, let’s look at the code:
Page inside iframe:
<html> <head> <title>框架内页</title> </head> <body> <div> <input id="txt1" name="txt1" type="text" value="测试" /> </div> </body> </html>
Parent class:
<iframe name="frame1" id="frame1" src="frm.html" frameborder="1" height="30"></iframe> <p> iframe1中文本框的值:</p> <p> <input type="button" name="Submit" value="getValue" onclick="getValue()" /> </p> <script type="text/javascript"> function getValue(){ var ofrm1 = document.getElementById("frame1").document; if (ofrm1==undefined) { ofrm1 = document.getElementById("frame1").contentWindow.document; var ff = ofrm1.getElementById("txt1").value; alert("firefox/chrome取值结果为:" + ff); } else { var ie = document.frames["frame1"].document.getElementById("txt1").value; alert("ie取值结果为:" + ie); } } </script>
I hope this article will be helpful to everyone in JavaScript programming.