jquery操作iframe的方法:父頁面和子頁面相互操作的方法


今天在弄jquery操作iframe中元素:先由iframe中的子頁面b.html給外面的父頁面a.html頁面傳值,再將a.html頁面計算機的值放到b.html頁面上,這里就用到子頁面和父頁面相互傳值,相互調用更自函數這些功能,這里我用一個簡單的例子來介紹一下這些方法。

a.html

<script language="javascript" src="http://www.aspbc.com/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function f()
{
    $('#a').contents().find("#bbb").val("ddd"); 
}
function fun()
{
    alert('彈出子頁面調用的函數');
}
</script>
<div id="maindiv">test</div>
<iframe id="a" name="a" src="b.html" width="600" height="400"></iframe><br />
<input type="button" value="給子頁面表單賦值" onclick="f()" />

b.html

<script language="javascript" src="http://www.aspbc.com/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function f()
{
    alert('開始調用父頁面函數');    
    $(window.parent.fun());
    $(window.parent.$("#maindiv").html("子頁面賦過來的值"));
}
</script>
<form name="cform"><input type="text" name="b" id="bbb" /><input name="btn" type="button" onclick="f()" value="調用父函數並給父頁面元素賦值" /></form>

 

屬性

new : HTML5 中的新屬性。

屬性 描述
align
  • left
  • right
  • top
  • middle
  • bottom

不贊成使用。請使用樣式代替。

規定如何根據周圍的元素來對齊此框架。

frameborder
  • 1
  • 0
規定是否顯示框架周圍的邊框。
height
  • pixels
  • %
規定 iframe 的高度。
longdesc URL 規定一個頁面,該頁面包含了有關 iframe 的較長描述。
marginheight pixels 定義 iframe 的頂部和底部的邊距。
marginwidth pixels 定義 iframe 的左側和右側的邊距。
name frame_name 規定 iframe 的名稱。
sandbox
  • ""
  • allow-forms
  • allow-same-origin
  • allow-scripts
  • allow-top-navigation
啟用一系列對 <iframe> 中內容的額外限制。
scrolling
  • yes
  • no
  • auto
規定是否在 iframe 中顯示滾動條。
seamless seamless 規定 <iframe> 看上去像是包含文檔的一部分。
src URL 規定在 iframe 中顯示的文檔的 URL。
srcdoc HTML_code 規定在 <iframe> 中顯示的頁面的 HTML 內容。
width
  • pixels
  • %
定義 iframe 的寬度。

 

var _body = window.parent;--------------------獲取這個div2的父級窗口,那么自然是這個body了;

var _iframe1 = _body.document,getElementById('rightMain');-------------------根據id獲取iframe1這個對象;

_iframe1.contentWindow.location.reload(true);-----------------------看到reload就該知道是刷新了這個iframe1了。

 

https://www.cnblogs.com/eco-just/p/9091018.html


免責聲明!

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



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