簡體   English   中英

使用jQuery刪除iframe中的body標簽

[英]Remove body tag within iframe with jQuery

我想從WooCommerce( http://www.shapur.com/product-category/fp-journe/ )的prettyPhoto燈箱插件中包含的iframe中刪除不必要的標頭。 當您單擊該頁面底部的單個產品按鈕時,它應刪除iframe中包含的body標簽。 iframe遵循相同的原始政策,事實並非如此。

我在同一域的此處創建了一個測試頁,效果很好: http : //www.shapur.com/test.php

燈箱有沖突嗎? 我只是不明白。 感謝您的協助。

這是測試頁的代碼:

<!DOCTYPE html>
<html>
<body>

<iframe id="myframe" src="http://shapur.com/index.php"></iframe>

<p>Click the button to change the style of the body tag contained in the iframe.</p>

<button onclick="myFunction()">Try it</button>

<script>
    function myFunction() {
        var x = document.getElementById("myframe");
        var y = x.contentDocument;
        y.body.style.display = "none";
}
</script>

</body>
</html>

由於它來自同一起源,所以為什么不使用jQuery load()函數:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<script type="text/javascript">
    function myFunction() {
       $(".myDiv").load("/index.php",function(data){
          $(data).find('body').css("display","none");
       });
    }
</script>

並有一個空的:

<div class="myDiv"></div>

這樣,您可以更輕松地使用代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM