获取iframe父页面声明的变量值,获取iframe父页面对象

iframe 就是一个内嵌的子窗口。

 

首先父页面index.htm

有一个变量

<html>

<head><script type="text/javascript">var isPhoto=1;</script></head>

<body>

<input type="text" />

<iframe scrolling="no" height="240" frameborder="0" style="width:588px !important; width:572px;" src="/frameIn.htm" name="frm_comment" ></iframe>

</body>

</html>

那么如何在Iframe页面获取父js变量,和对象呢?

frameIn.htm页面代码

<script type="text/javascript">

alert(parent.isPhoto);

alert(parent.document.getElementById('yq').value);

//如果是jquery取对象,可以这样:$('#objID',parent.document)

alert($('#yq', parent.document).val());

</script>

相关文章:

  • 2022-12-23
  • 2020-07-22
  • 2021-07-11
  • 2022-02-15
  • 2021-11-19
  • 2022-01-14
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案