首先有使用taobao的人应该会发现,淘宝的首页弹窗出现有两种情况:

1.你没有使用拦截插件。

那么在页面打开时广告窗口就直接弹出了。

2.在你有使用拦截插件。

在你第一次点击页面连接时弹出。

有们直接看它的代码分析一下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
E.on(window, 'load', function() {
        //使用cookie记录24小时内是否已打开过
        if (TB.bom.getCookie('_tb_defaultbackpop_') == 1) return;
        var saveStatus = function() {
        var nowDate = new Date();
        var nowTime = nowDate.getHours()*3600 + nowDate.getMinutes()*60
                      + nowDate.getSeconds();
        var DAY = 24*3600;
        var leaveTime = DAY - nowTime;
                TB.bom.setCookie('_tb_defaultbackpop_', 1,
                             leaveTime/DAY, document.domain, '/');
        }
        var createPopup = function() {//弹窗函数
        var adPopup = window.open('about:blank','_backad','width='+(pw||760)+
                            ',height='+(ph||480)+'
                     ,toolbar=no,location=no,directories=no,status=yes,resizable=no,scrollbars=no');
                adPopup.blur();
                adPopup.opener.focus();
                adPopup.location = adUrl;
    }
    var popAd = function() {
        try {
            createPopup();//载入时打开
        } catch (e) {//如果被拦截执行这里,把弹窗加到document的click事件中
            $E.on(document, 'click', popAd2);
        } finally {
                        saveStatus();
                }
    }
 
    var popAd2 = function(ev) {
        try {
            var nodeType = $E.getTarget(ev).tagName.toLowerCase();
            if ('input' == nodeType || 'select' == nodeType 
                     || 'option' == nodeType || 'button' == nodeType) {
                return;
            }
        } catch (e) {}
        //这里是判断如果点击的是这几种元件就不弹窗
        $E.removeListener(document, 'click', arguments.callee);
        try {
            createPopup();
        } catch (e) {}
                saveStatus();
    }
 
    var adUrl = 'http://www.taobao.com/promotion/defaultbackpop.html';
    var pw = '760', ph = '480';
 
        setTimeout(popAd, 2000);
});