Webbrowser1删除元素<div>

时间:2017-01-22 20:54:51

标签: html vb.net webbrowser-control

我试图删除此div代码的所有内容&#34;广告&#34;:

&#13;
&#13;
<div id="ads">
    <div id="ad_overlay" style="position: absolute; left: 20px; top: 22px; width: 944px; height: 786px;z-index:911;">
        <iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://hdcast.org/ads/ad3.php" width="635" height="329" style="display: none !important;">
        </iframe>
    </div>
    <div id="close" style="position:absolute;top:29px;left:190px;border:0;z-index:10000;" class="">
        <a href="javascript:void(0)" onclick="removeOverlayHTML()">
            <img src="http://www.hdcast.org/images/close_button.png" height="15" width="15">
        </a>
    </div>
</div>
&#13;
&#13;
&#13;

我通过这样做删除了ad_overlay

Form1.WebBrowser1.document.GetElementById("ad_overlay").OuterHtml = ""

但它对ad无效。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
var ad = document.getElementById("ads");
function removeOverlayHTML() {
  ad.remove();
  }
&#13;
<div id="ads">
<div id="ad_overlay" style="position: absolute; left: 20px; top: 22px; width: 944px; height: 786px;z-index:911;"><iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://hdcast.org/ads/ad3.php" width="635" height="329" ></iframe></div>
<div id="close" style="position:absolute;top:29px;left:190px;border:0;z-index:10000;" class="">
<a href="javascript:void(0)" onclick="removeOverlayHTML()"><img src="http://www.hdcast.org/images/close_button.png" height="15" width="15"></a></div>
</div>
&#13;
&#13;
&#13;

此功能可让您删除包含其他两个<div>的{​​{1}},其中包含简单的代码行<div>和变量ad.remove();到元素。