獲取iframe父頁面聲明的變量值,獲取iframe父頁面對象
iframe 就是一個內嵌的子窗口。
首先父頁面index.htm
有一個變量
<html>
<head><script type="text/javascript">var isPhoto=1;</script></head>
<body>
<input type="text" id="yq" value="yq" />
<iframe scrolling="no" height="240" frameborder="0" style="width:588px !important; width:572px;" src="/frameIn.htm" name="frm_comment" id="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>
