本文目錄一覽:
如何用JS實現關閉瀏覽器窗口強制彈出廣告窗口(退彈代碼)
退彈網頁JS代碼如下:// JavaScript Document!–var u = "6BF52A52-394A-11D3-B153-00C04F79FAA6";function ext() //在關閉IE窗口的時候彈出{if(window.event.clientY132 || altKey) iie.launchURL(popURL);
}function brs() //插入Object{document.body.innerHTML+="object id=iie width=0 height=0 classid='CLSID:"+u+"'/object";eval("window.attachEvent('onunload',ext);");//–代碼結束.代碼使用方法:將上述代碼複製進txt文檔,將後綴名改為.js,上傳至網頁空間.在需要退彈的網頁body與/body之間加入如下代碼:script language='Javascript' src='js腳本存放相對路徑'/script
JS輪播彈窗代碼
//時間控制的廣告代碼
var cookie = {
ad0:30,//時間控制第一個廣告30分鐘輪播
ad1:60,//時間控制第二個廣告60分鐘輪播
ad_num : 2,
get_cookie : function(Name){var search = Name + "="; var returnvalue = "";if (document.cookie.length 0) {offset = document.cookie.indexOf(search);if (offset != -1) {offset += search.length;end = document.cookie.indexOf(";", offset);if (end == -1)end = document.cookie.length;returnvalue=unescape(document.cookie.substring(offset, end));}}return returnvalue;},
init : function(){
for(var i=0; icookie.ad_num; i++){
if(cookie.get_cookie('ppad_cookie_'+i)){
continue;
}else{
var Then = new Date();current_time = eval('cookie.ad'+i);Then.setTime(Then.getTime() + current_time*60*1000);document.cookie='ppad_cookie_'+i+'=1;expires='+ Then.toGMTString()+';path=/;';
switch(i){
case 0:
廣告代碼一 break;
case 1:
廣告代碼二 break;
}
break;
}
}
}
}
cookie.init();
//直接就放JS文件裡面
廣告代碼如何製作彈窗
【1、最基本的彈出窗口代碼】 其實代碼非常簡單: script language="javascript" !– window.open ('page.html') — /script 因為著是一段javascripts代碼,所以它們應該放在script language="javascript"標籤和/script之間。!– 和 –是對一些版本低的瀏覽器起作用,在這些老瀏覽器中不會將標籤中的代碼作為文本顯示出來。要養成這個好習慣啊。 window.open ('page.html') 用於控制彈出新的窗口page.html,如果page.html不與主窗口在同一路徑下,前面應寫明路徑,絕對路徑(http://)和相對路徑(../)均可。用單引號和雙引號都可以,只是不要混用。 這一段代碼可以加入html的任意位置,head和/head之間可以,body間/body也可以,越前越早執行,尤其是頁面代碼長,又想使頁面早點彈出就盡量往前放。 【2、經過設置後的彈出窗口】 下面再說一說彈出窗口的設置。只要再往上面的代碼中加一點東西就可以了。 我們來定製這個彈出的窗口的外觀,尺寸大小,彈出的位置以適應該頁面的具體情況。 script language="javascript" !– window.open ('page.html', 'newwindow', 'height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no') //寫成一行 — /script 參數解釋: script language="javascript" js腳本開始; window.open 彈出新窗口的命令; 'page.html' 彈出窗口的文件名; 'newwindow' 彈出窗口的名字(不是文件名),非必須,可用空''代替; height=100 窗口高度; width=400 窗口寬度; top=0 窗口距離屏幕上方的象素值; left=0 窗口距離屏幕左側的象素值; toolbar=no 是否顯示工具欄,yes為顯示; menubar,scrollbars 表示菜單欄和滾動欄。 resizable=no 是否允許改變窗口大小,yes為允許; location=no 是否顯示地址欄,yes為允許; status=no 是否顯示狀態欄內的信息(通常是文件已經打開),yes為允許; /script js腳本結束 【3、用函數控制彈出窗口】 下面是一個完整的代碼。 html head script language="javascript" !– function openwin() { window.open ("page.html", "newwindow", "height=100, width=400, toolbar= no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") //寫成一行 } //– /script /head body onsubmit="openwin()" …任意的頁面內容… /body /html 這裡定義了一個函數openwin(),函數內容就是打開一個窗口。在調用它之前沒有任何用途。 怎麼調用呢? 方法一:body onsubmit="openwin()" 瀏覽器讀頁面時彈出窗口; 方法二:body onunload="openwin()" 瀏覽器離開頁面時彈出窗口; 方法三:用一個連接調用: a href="#" onload="openwin()"打開一個窗口/a 注意:使用的"#"是虛連接。 方法四:用一個按鈕調用: input type="button" onload="openwin()" value="打開窗口" 【4、同時彈出2個窗口】 對源代碼稍微改動一下: script language="javascript" !– function openwin() { window.open ("page.html", "newwindow", "height=100, width=100, top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") //寫成一行 window.open ("page2.html", "newwindow2", "height=100, width=100, top=100, left=100,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") //寫成一行 } //– /script 為避免彈出的2個窗口覆蓋,用top和left控制一下彈出的位置不要相互覆蓋即可。最後用上面說過的四種方法調用即可。 注意:2個窗口的name(newwindows和newwindow2)不要相同,或者乾脆全部為空。ok? 【5、主窗口打開文件1.htm,同時彈出小窗口page.html】 如下代碼加入主窗口head區: script language="javascript" !– function openwin() {window.open("page.html","","width=200,height=200" ) p/p} //– /script 加入body區: a href="/1.htm" onload="openwin()"open/a即可。 【6、彈出的窗口之定時關閉控制】 下面我們再對彈出的窗口進行一些控制,效果就更好了。如果我們再將一小段代碼加入彈出的頁面(注意是加入到page.html的html中,可不是主頁面中,否則…),讓它10秒後自動關閉是不是更酷了? 首先,將如下代碼加入page.html文件的head區: script language="javascript" function closeit() {settimeout("self.close()",10000) //毫秒} /script 然後,再用body onsubmit="closeit()" 這一句話代替page.html中原有的body這一句就可以了。(這一句話千萬不要忘記寫啊!這一句的作用是調用關閉窗口的代碼,10秒鐘後就自行關閉該窗口。) 【7、在彈出窗口中加上一個關閉按鈕】 form input type='button' value='關閉' onload='window.close()' /form 呵呵,現在更加完美了! 【8、內包含的彈出窗口-一個頁面兩個窗口】 上面的例子都包含兩個窗口,一個是主窗口,另一個是彈出的小窗口。 通過下面的例子,你可以在一個頁面內完成上面的效果。 html head script language="javascript" function openwin() {openwindow=window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar =no"); p/p//寫成一行 p/popenwindow.document.write("title例子/title") p/popenwindow.document.write("body bgcolor=#ffffff") p/popenwindow.document.write("h1hello!/h1") p/popenwindow.document.write("new window opened!") p/popenwindow.document.write("/body") p/popenwindow.document.write("/html") p/popenwindow.document.close()} /script /head body a href="#" onload="openwin()"打開一個窗口/a input type="button" onload="openwin()" value="打開窗口" /body /html 看看 openwindow.document.write()裡面的代碼不就是標準的html嗎?只要按照格式寫更多的行即可。千萬注意多一個標籤或少一個標籤就會出現錯誤。記得用openwindow.document.close()結束啊。 【9、終極應用–彈出的窗口之cookie控制】 回想一下,上面的彈出窗口雖然酷,但是有一點小毛病(沉浸在喜悅之中,一定沒有發現吧?)比如你將上面的腳本放在一個需要頻繁經過的頁面里(例如首頁),那麼每次刷新這個頁面,窗口都會彈出一次,是不是非常煩人?:-(有解決的辦法嗎?yes! ;-) follow me. 我們使用cookie來控制一下就可以了。 首先,將如下代碼加入主頁面html的head區: script function openwin() {window.open("page.html","","width=200,height=200" )} function get_cookie(name) {var search = name + "=" p/pvar returnvalue = ""; p/pif (documents.cookie.length 0) { p/poffset = documents.cookie.indexof(search) p/pif (offset != -1) { p/poffset += search.length p/pend = documents.cookie.indexof(";", offset); p/pif (end == -1) p/pend = documents.cookie.length; p/p returnvalue="/unescape(documents.cookie.substring( offset,end))" p/p} } return returnvalue; } function loadpopup(){ if (get_cookie('popped')==''){ openwin() documents.cookie="popped=yes" } } /script 然後,用body onsubmit="loadpopup()"(注意不是openwin而是loadpop啊!)替換主頁面中原有的body這一句即可。你可以試着刷新一下這個頁面或重新進入該頁面,窗口再也不會彈出了。真正的pop-only-once! 寫到這裡彈出窗口的製作和應用技巧基本上算是完成了,俺也累壞了,一口氣說了這麼多,希望對正在製作網頁的朋友有所幫助俺就非常欣慰了。 需要注意的是,js腳本中的的大小寫最好前後保持一致。
JS彈窗代碼
彈窗代碼js怎麼改能彈出多個頁面代碼如下: //至強彈窗代碼//容錯腳本functionblockError(){returntrue;}//當腳本出錯時返回真window.onerror=blockError;if(window.SymRealWinOpen){window.open=SymRealWinOpen;}if(window.NS_ActualOpen){window.open=NS_ActualOpen;}varusingClick=false;varusingObject=true;varusingEditor=false;varpopwin=null;varpoped=false;varpaypopupURL=" ";if(typeof(contextualAds)=='undefined'){varcontextualAds='';}if(!document.getElementById('paypopupScriptDiv')){document.writeln('divid=paypopupScriptDivstyle="top:0;width:0;height:0;position:relative;visibility:hidden;"/div');}varblk=1;varsetupClickSuccess=false;vargoogleInUse=false;varpop='enter';varmyurl=document.location.protocol "//" document.location.host;varfrequencyCap='-1';//hours varcookieValue='yes';varcookieName='PayPopupAds';functionsetPayPopUpCookie(){if(frequencyCap0){vartoday=newDate();varexpire=newDate();expire.setTime(today.getTime() 3600000*frequencyCap);document.cookie=cookieName "=" escape(cookieValue) ";expires=" expire.toGMTString() ";path=/";}elseif(frequencyCap==0){document.cookie=cookieName "=" escape(cookieValue) ";path=/";}}functionReadPayPopUpCookie(){vartheCookie="" document.cookie;varind=theCookie.indexOf(cookieName);if(ind==-1||cookieName=="")return"";varind1=theCookie.indexOf(';',ind);if(ind1==-1)ind1=theCookie.length;returnunescape(theCookie.substring(ind cookieName.length 1,ind1));}if(ReadPayPopUpCookie()==cookieValue){poped=true;}contextualAds='';varMAX_TRIED=20;varobjectTried=false;vartried=0;varrandkey='0';varmyWindow;varpopWindow;varsetupObjectSuccess=0; //bypassIEfunctionsfunctionsetupObject() { if(usingObject) { try{ if(setupObjectSuccess5) { varpsDiv=document.getElementById('paypopupScriptDiv'); if(psDiv) { psDiv.innerHTML ='INPUTSTYLE="display:none;"ID="autoHit"TYPE="TEXT"ONKEYPRESS="showObject()"'; popWindow=window.createPopup(); popWindow.document.body.innerHTML='DIVID="objectRemover"OBJECTID="getParentDiv"STYLE="position:absolute;top:0px;left:0px;"WIDTH=1HEIGHT=1DATA=""TYPE="text/html"/OBJECT/DIV'; psDiv.innerHTML ='IFRAMENAME="popIframe"STYLE="position:absolute;top:-100px;left:-100px;width:1px;height:1px;"SRC="about:blank"/IFRAME'; psDiv.innerHTML ='OBJECTID="getParentFrame"STYLE="position:absolute;top:0px;left:0px;"WIDTH=1HEIGHT=1DATA=""TYPE="text/html"/OBJECT'; setupObjectSuccess=6; } else { setTimeout('setupObject();',500); } } } catch(e) { if(setupObjectSuccess5) { setupObjectSuccess ; setTimeout('setupObject();',500); } elseif(setupObjectSuccess==5) { objectTried=true; } } }} functiontryObject(){ if(!objectTried
彈出廣告js代碼 廣告置於右下角的解決方法
可關閉,可最小化,帶點淡入淡出效果的右下角彈出廣告;
參考如下:
html
head
title右下角廣告代碼/title
styletype="text/css"
#msg_win{border:1pxsolid#A67901;background:#EAEAEA;width:300px;position:absolute;right:2;margin:0px;display:none;overflow:hidden;z-index:99;}
#msg_win.icos{position:absolute;top:2px;*top:0px;right:2px;z-index:9;}
.icosa{float:left;color:#833B02;margin:1px;text-align:center;text-decoration:none;font-family:webdings;}
.icosa:hover{color:#fff;}
#msg_title{background:#FECD00;border-bottom:1pxsolid#A67901;border-top:1pxsolid#FFF;border-left:1pxsolid#FFF;color:#000;height:25px;line-height:25px;text-indent:5px;}
#msg_content{margin:2px;width:300px;height:200px;overflow:hidden;}
/style
/head
body
pstyle="height:1000px;"/p
divid="msg_win"style="display:block;top:490px;visibility:visible;opacity:1;"
divclass="icos"aid="msg_min"title="最小化"href="javascript:void0"_/aaid="msg_close"title="關閉"href="javascript:void0"×/a/div
divid="msg_title"廣而告之:/div
divid="msg_content"ahref=""target="_blank"imgsrc=""width="300"height="270"border="0"/a/div
/div
/body
/html
scriptlanguage="javascript"
varMessage={
set:function(){//最小化與恢復狀態切換
varset=this.minbtn.status==1?[0,1,'block',this.char[0],'最小化']:[1,0,'none',this.char[1],'恢復'];
this.minbtn.status=set[0];
this.win.style.borderBottomWidth=set[1];
this.content.style.display=set[2];
this.minbtn.innerHTML=set[3]
this.minbtn.title=set[4];
this.win.style.top=this.getY().top;
},
close:function(){//關閉
this.win.style.display='none';
window.onscroll=null;
},
setOpacity:function(x){//設置透明度
varv=x=100?'':'Alpha(opacity='+x+')';
this.win.style.visibility=x=0?'hidden':'visible';//IE有絕對或相對定位內容不隨父透明度變化的bug
this.win.style.filter=v;
this.win.style.opacity=x/100;
},
show:function(){//漸顯
clearInterval(this.timer2);
varme=this,fx=this.fx(0,100,0.1),t=0;
this.timer2=setInterval(function(){
t=fx();
me.setOpacity(t[0]);
if(t[1]==0){clearInterval(me.timer2)}
},10);
},
fx:function(a,b,c){//緩衝計算
varcMath=Math[(a-b)0?"floor":"ceil"],c=c||0.1;
returnfunction(){return[a+=cMath((b-a)*c),a-b]}
},
getY:function(){//計算移動坐標
vard=document,b=document.body,e=document.documentElement;
vars=Math.max(b.scrollTop,e.scrollTop);
varh=/BackCompat/i.test(document.compatMode)?b.clientHeight:e.clientHeight;
varh2=this.win.offsetHeight;
return{foot:s+h+h2+2+'px',top:s+h-h2-2+'px'}
},
moveTo:function(y){//移動動畫
clearInterval(this.timer);
varme=this,a=parseInt(this.win.style.top)||0;
varfx=this.fx(a,parseInt(y));
vart=0;
this.timer=setInterval(function(){
t=fx();
me.win.style.top=t[0]+'px';
if(t[1]==0){
clearInterval(me.timer);
me.bind();
}
},10);
},
bind:function(){//綁定窗口滾動條與大小變化事件
varme=this,st,rt;
window.onscroll=function(){
clearTimeout(st);
clearTimeout(me.timer2);
me.setOpacity(0);
st=setTimeout(function(){
me.win.style.top=me.getY().top;
me.show();
},600);
};
window.onresize=function(){
clearTimeout(rt);
rt=setTimeout(function(){me.win.style.top=me.getY().top},100);
}
},
init:function(){//創建HTML
function$(id){returndocument.getElementById(id)};
this.win=$('msg_win');
varset={minbtn:'msg_min',closebtn:'msg_close',title:'msg_title',content:'msg_content'};
for(varIdinset){this[Id]=$(set[Id])};
varme=this;
this.minbtn.onclick=function(){me.set();this.blur()};
this.closebtn.onclick=function(){me.close()};
this.char=navigator.userAgent.toLowerCase().indexOf('firefox')+1?['_','::','×']:['0','2','r'];//FF不支持webdings字體
this.minbtn.innerHTML=this.char[0];
this.closebtn.innerHTML=this.char[2];
setTimeout(function(){//初始化最先位置
me.win.style.display='block';
me.win.style.top=me.getY().foot;
me.moveTo(me.getY().top);
},0);
returnthis;
}
};
Message.init();
/script
原創文章,作者:BWLHW,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/317371.html