獲取iframe父頁面聲明的變量值,獲取iframe父頁面對象


獲取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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM