首页 > 语言 > JavaScript > 正文

不侵占父窗口的超强退弹代码

2024-05-06 15:46:30
字体:
来源:转载
供稿:网友

测试环境为XP SP3 IE6.0下。

  1. function setCookie(name,value,days){  
  2.         var exp=new Date();  
  3.         exp.setTime(exp.getTime() + days*60*60*1000);  
  4.         var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));  
  5.         document.cookie=name+"="+escape(value)+";expires="+exp.toGMTString();  
  6. }  
  7. function getCookie(name){  
  8.         var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));  
  9.         if(arr!=null){  
  10.                 return unescape(arr[2]);  
  11.                 return null;  
  12.         }  
  13. }  
  14. function delCookie(name){  
  15.         var exp=new Date();  
  16.         exp.setTime(exp.getTime()-1);  
  17.         var cval=getCookie(name);  
  18.         if(cval!=null){  
  19.                 document.cookie=name+"="+cval+";expires="+exp.toGMTString();  
  20.         }  
  21. }  
  22.  
  23. document.write('<object id="stb" height="1" width="1" classid="clsid:2D360201-FFF5-11d1-8D03-00A0C959BC0A">');  
  24. document.write('        <param name="ActivateActiveXControls" value="1">');  
  25. document.write('        <param name="ActivateApplets" value="1">');  
  26. document.write('</object>');  
  27.  
  28. var popurl = 'http://www.Vevb.com/';  
  29. var popDialogOptions = "top=0,left=0,toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=1024px,height=572px";  
  30.  
  31. function popwin(popurl,target,popDialogOptions){  
  32.         stb.DOM.Script.window.open(popurl,target,popDialogOptions);  
  33. }  
  34.  
  35. window.onbeforeunload = function (){  
  36.         if(!getCookie("tuitan")){  
  37.                 setCookie("tuitan","yes",12);popwin(popurl,'_blank',popDialogOptions);  
  38.         }  

使用说明:
把以上代码存为.js,然后在需要的网页调用即可。
1.退弹网址,var popurl = 'http://www.Vevb.com/'; 请修改为你自己的网址,
2.时间控制,setCookie("tuitan","yes",12); 其中12代表12小时退弹一次;如果setCookie("tuitan","yes",24);则代表24小时退弹一次,

其他:这个退弹代码是哥之前发的修改优化版,代码绝对整洁、直观,其他浏览器没测试,自己看着用吧。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选