目前不易被拦截的弹出窗口方法(淘宝弹出广告实现方法)
2008-8-30 17:07:14 | At WEB开发 | Comments 0 | View 1563
这几天需要有一个新的产品需要推广,想依靠另一个流量较大的网站来拉动,但是现在的弹出广告几乎都被拦截掉了,让我很头痛。
突然间想到了淘宝有时候,在浏览时会时不时的弹出广告页面,XP并没有拦住,是什么原理呢?经过我猜想、研究,得出这样的结论。淘宝用JS给每个链接(也就是A标签)都加上一个弹出窗口的代码。然后判断COOKIES,对于没有弹出过广告的用户点击任意一个链接时,就弹出,并写入COOKIES。如果弹出过的用户,点击所有链接就正常链接,不弹出了。具体代码如下:
//写入COOKIE
function setCookie(name,value){
var Days = 1;
var exp = new Date();
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
//读取COOKIE
function getCookie(name){
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg)) return unescape(arr[2]);
else return null;
}
window.attachEvent("onload", function(){
if (getCookie("popWin")) return false;
var o = document.getElementsByTagName("a");
for (var i=0; i<o.length; i++){
o[i].attachEvent("onclick", function(){
if (!getCookie("popWin")){
setCookie("popWin", "true");
window.open("http://www.huixue.cc", "popWin", "height=700, width=500, top=0, left=1000, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes, location=yes, status=yes");
window.focus();
}
});
}
});
function setCookie(name,value){
var Days = 1;
var exp = new Date();
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
//读取COOKIE
function getCookie(name){
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg)) return unescape(arr[2]);
else return null;
}
window.attachEvent("onload", function(){
if (getCookie("popWin")) return false;
var o = document.getElementsByTagName("a");
for (var i=0; i<o.length; i++){
o[i].attachEvent("onclick", function(){
if (!getCookie("popWin")){
setCookie("popWin", "true");
window.open("http://www.huixue.cc", "popWin", "height=700, width=500, top=0, left=1000, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes, location=yes, status=yes");
window.focus();
}
});
}
});
近期相关评论
发表评论
正在载入数据...