如何删除html标记和head标记之间的iframe标记?

时间:2016-11-22 03:49:39

标签: javascript jquery html css3 iframe

我想删除html和head标签之间出现的iframe。它不会出现在桌面版中。每当我在移动版本上打开网站时,它都会显示在HTML和Head标记之间。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<html>
  
  <iframe scrolling="no" style="background-color: transparent !important; display: block !important; z-index: 2147483637 !important; border: none !important; width: 320px !important; height: 66.6667px !important; position: fixed !important; bottom: 0px !important; left: 0px !important;"></iframe>
  
  <head id="ctl00_headerMaster">
  <title>How to get iframe between html tag and head tag</title>
    
  </head>
  
  <body id="ctl00_edubody">
 
    <h1>How to get iframe between html tag and head tag</h1>
    
    
  </body>
  
 </html>

1 个答案:

答案 0 :(得分:1)

首先,将iframe作为HTML标记的直接子项无效。我们无法预测浏览器如何处理它,因此下面的代码可能会失败。

使用prevAll()获取iframe并使用remove()方法删除。

$('head').prevAll('iframe').remove();

或者获取HTML代码的直接子项并将其删除。

$('html > iframe:first-child').remove();