js仿淘宝弹窗代码示例

发布时间:2020-06-15编辑:脚本学堂
分享一个js弹窗代码,摘自淘宝的弹窗广告代码,需要的朋友参考下。

例子,js弹窗代码。
 

复制代码 代码示例:
$E.on(window, 'load', function() {
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) {
         $E.on(document, 'click', popAd2);
       } finally {
saveStatus();
}
}
var popAd2 = function() {
       $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);
});