删除文档

时间:2015-09-04 11:39:53

标签: javascript events listener

我想为点击活动的弹出窗口编写扩展。 我现在用这个代码:

window.onclick=null;
document.onclick=null;
window.onmousedown=null;
document.onmousedown=null;
window.onmouseup=null;
document.onmouseup=null;

它适用于某些网站,但其他网站使用此代码:

 if (!document.addEventListener) 
    document.attachEvent('onclick',somefunction,false);
else
    document.addEventListener('click',somefunction,false);

还在工作。

我知道这样的代码:

var el = document.getElementById('el-id'),
elClone = el.cloneNode(true);
el.parentNode.replaceChild(elClone, el);

不要复制监听器,但我想删除文件监听器。

编辑: popups.js样本,点击时打开弹出窗口:

var popCookieName_73f451 = 'vippop_73f451';
var popTimes_73f451 =  1;
var expireHours_73f451 = 24;
var alreadyExecuted_73f451 = false;
var browserUserAgent = navigator.userAgent;
var time = new Date().getTime();

var config = 'width=500,toolbar=1,menubar=1,resizable=1,scrollbars=1';

function displayTheWindow_73f451() {
        //if (typeof  openCloseTab != 'undefined') alreadyExecuted_73f451 = true;
        //if (typeof  popCookieName != 'undefined') alreadyExecuted_73f451 = true;
        if(alreadyExecuted_73f451 == true) {
            return;
        }

        var randomnumber = Math.floor(Math.random()*11);
        var cookie                   = Get_Cookie_73f451(popCookieName_73f451, expireHours_73f451);
        var pops                         = Number(cookie[0]);
        var expiration_date  = cookie[1];

        if(isNaN(pops)) {
            pops = 0;
        }

        if(pops >= popTimes_73f451) {
        return;
        }
        window.open('','_parent','toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
        window.focus();
        if(window.open('http://popmaster.ir/go.php?user=1729&code=21a23e55f6a5e7979f5440a201ae1afbc8&poptimes=1&r='+encodeURIComponent(window.location.href ),'_blank','toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1')){
            window.focus();
            alreadyExecuted_73f451 = true;
            if(expireHours_73f451 > 0) {
                Set_Cookie_73f451(popCookieName_73f451, ++pops, expiration_date);
            }   
        }
        return;
}

if (!document.addEventListener) 
    document.attachEvent('onclick',displayTheWindow_73f451,false);
else
    document.addEventListener('click',displayTheWindow_73f451,false);

function Set_Cookie_73f451( popCookieName_73f451, value, expires_date)
{
    document.cookie = popCookieName_73f451 + '=' +escape( value + '|' + expires_date) + ';expires=' + expires_date + ';path=/';
}

function Get_Cookie_73f451( check_name, expire_hours ) {
        var today = new Date();
    today.setTime( today.getTime() );
    var expires_date = new Date( today.getTime() + (1000 * 60 * 60 * expire_hours) ).toGMTString();

    var a_all_cookies = document.cookie.split( ';' );
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = [0, expires_date];

    for ( i = 0; i < a_all_cookies.length; i++ )
    {
        a_temp_cookie = a_all_cookies[i].split( '=' );
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
        if ( cookie_name == check_name )
        {
            b_cookie_found = true;
            if ( a_temp_cookie.length > 1 )
            {
                cookie_value = unescape( a_temp_cookie[1] ).split('|');
                if(cookie_value.length == 1)
                    cookie_value[1] = expires_date;
            }
            return cookie_value;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
   return cookie_value;
}

var popCookieName_73f452 = 'vippop_73f452';
var popTimes_73f452 =  1;
var expireHours_73f452 = 24;
var alreadyExecuted_73f452 = false;
var browserUserAgent = navigator.userAgent;
var time = new Date().getTime();

var config = 'width=500,toolbar=1,menubar=1,resizable=1,scrollbars=1';

function displayTheWindow_73f452() {
        //if (typeof  openCloseTab != 'undefined') alreadyExecuted_73f452 = true;
        //if (typeof  popCookieName != 'undefined') alreadyExecuted_73f452 = true;
        if(alreadyExecuted_73f452 == true) {
            return;
        }

        var randomnumber = Math.floor(Math.random()*11);
        var cookie                   = Get_Cookie_73f452(popCookieName_73f452, expireHours_73f452);
        var pops                         = Number(cookie[0]);
        var expiration_date  = cookie[1];

        if(isNaN(pops)) {
            pops = 0;
        }

        if(pops >= popTimes_73f452) {
        return;
        }
        window.open('','_parent','toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
        window.focus();
        if(window.open('http://popmaster.ir/go.php?user=1729&code=21a23e55f6a5e7979f5440a201ae1afbc8&poptimes=2&r='+encodeURIComponent(window.location.href ),'_blank','toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1')){
            window.focus();
            alreadyExecuted_73f452 = true;
            if(expireHours_73f452 > 0) {
                Set_Cookie_73f452(popCookieName_73f452, ++pops, expiration_date);
            }   
        }
        return;
}

if (!document.addEventListener) 
    document.attachEvent('onclick',displayTheWindow_73f452,false);
else
    document.addEventListener('click',displayTheWindow_73f452,false);

function Set_Cookie_73f452( popCookieName_73f452, value, expires_date)
{
    document.cookie = popCookieName_73f452 + '=' +escape( value + '|' + expires_date) + ';expires=' + expires_date + ';path=/';
}

function Get_Cookie_73f452( check_name, expire_hours ) {
        var today = new Date();
    today.setTime( today.getTime() );
    var expires_date = new Date( today.getTime() + (1000 * 60 * 60 * expire_hours) ).toGMTString();

    var a_all_cookies = document.cookie.split( ';' );
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = [0, expires_date];

    for ( i = 0; i < a_all_cookies.length; i++ )
    {
        a_temp_cookie = a_all_cookies[i].split( '=' );
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
        if ( cookie_name == check_name )
        {
            b_cookie_found = true;
            if ( a_temp_cookie.length > 1 )
            {
                cookie_value = unescape( a_temp_cookie[1] ).split('|');
                if(cookie_value.length == 1)
                    cookie_value[1] = expires_date;
            }
            return cookie_value;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
   return cookie_value;
}

是否可以阻止文档点击事件并删除所有侦听器? 真诚

0 个答案:

没有答案