亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從另一個iFrame中清除iFrame的內容

如何從另一個iFrame中清除iFrame的內容

如何從另一個iFrame中清除iFrame的內容我wrapperPage.html和一個<iframe class="header"和<iframe class="pageBody"。在header有一個鏈接,<a class="clearLink"點擊時應該清除內容pageBody。到目前為止,上述想法的以下實現不起作用。請幫我解決這個問題。請注意,header并且pageBody每個都從不同的包含文件加載。wrapperPage.html<div class=non-floater>     <iframe class="header" src="header.html"></iframe>     <iframe class="pageBody" src="pageBody.html" /> </div>header.html:<script type="text/javascript">     $(document).ready(function() {         $(".clearLink").on("click", function() {             $('.pageBody').contents().find("body").html('');         });     });</script><a class="clearLink" href="#">Navigation Button</a>pageBody.html:<div class="panel-body">This is the body</div>
查看完整描述

2 回答

?
墨色風雨

TA貢獻1853條經驗 獲得超6個贊

嘗試使用頻道消息

wrapperPage.html

<body><div class=non-floater>
    <iframe class="header" src="header.html"></iframe>
    <iframe class="pageBody" src="pageBody.html" /> </div><script>
  var channel = new MessageChannel();
  var header = $(".header")[0].contentWindow;
  var pageBody = $(".pageBody")[0].contentWindow;
  header.onload = function() {
    this.postMessage("","*", [channel.port2])
  };

  channel.port1.onmessage = function(e) {
    if (e.data === "clicked") {
      $(pageBody.document.body).html("")
    }
  }</script></body>

header.html

<body><a class="clearLink" href="#">Navigation Button</a><script>
  var port;

  onmessage = function(e) {
    port = e.ports[0];
  }

  $(".clearLink").on("click", function(e) {
      port.postMessage("clicked");
  });</script></body>


查看完整回答
反對 回復 2019-08-23
?
回首憶惘然

TA貢獻1847條經驗 獲得超11個贊

您可以從iFrame獲取主窗口的引用,如下所示: Window.Parent引用

然后,您可以指定一個事件來捕獲主窗口中的觸發器或函數(或僅在其他iFrame中)來管理它。

例如 :

  • 在pageBody.html中編寫與自定義事件關聯的函數。

  • header.htmliFrame中的點擊功能獲取窗口參考。

  • 搜索已分配自定義事件的目標元素。

  • 點燃活動

我希望它可以幫到你。


查看完整回答
反對 回復 2019-08-23
  • 2 回答
  • 0 關注
  • 1267 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號