Home  >  Article  >  Web Front-end  >  js method to implement iframe frame value (compatible with IE, firefox, chrome, etc.)_javascript skills

js method to implement iframe frame value (compatible with IE, firefox, chrome, etc.)_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:29:441062browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn