ssttm169 / remove-h5-ads

专冶各种H5的嵌入垃圾广告
https://juejin.im/post/5b06feb46fb9a07a9d70bf04
31 stars 6 forks source link

Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node. #1

Open yang-mr opened 5 years ago

yang-mr commented 5 years ago

Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.

ssttm169 commented 5 years ago

把你代码,发给我看看

yang-mr commented 5 years ago
    var del_times = 0, deTimer = null;
    function adGo() {
        var iframe = document.getElementsByTagName('iframe')[0];
        if(iframe){
            console.log(iframe)
            var bodyNode = {tagName:''}, iframeParent, targetNode = iframe.parentNode;
            while (bodyNode.tagName != 'BODY'){
                bodyNode = targetNode;
                if(bodyNode.tagName != 'BODY'){
                    iframeParent = targetNode;
                    targetNode = targetNode.parentNode;
                }
            }
            if(iframeParent) //如果iframe有父类
                bodyNode.removeChild(iframeParent);
            else
                bodyNode.removeChild(iframe);
        }
        del_times++;
        //这里是执行50次, 每次200ms, 意思在10秒以内删除垃圾广告。
        if (del_times > 50) window.clearInterval(deTimer)
    }

    //抢先 删除 嵌入广告
    (function(){adGo();}())

    deTimer = self.setInterval(adGo, 200);
ssttm169 commented 5 years ago

这个我知道啊,我所指的是html的部分~~

yang-mr commented 5 years ago

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


正在上传头像...
yang-mr commented 5 years ago

`<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


正在上传头像...
`
yang-mr commented 5 years ago

兄弟人呢?