弹窗代码汇总
超完美弹窗代码
功能:5小时弹一次+背后弹出+自动适应不同分辩率+准全屏显示
代码:
<script>
function openwin(){
window.open(
http://www.6882.com,"pop1","width="+/(window.screen.width-15)+",height="+(window.screen.height-170)+",left=0,top=0,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,status=yes")
setTimeout("focus();",5);
}
function get_cookie(Name) {
var search = Name + "="
var return&#118alue = "";
if (documents&#46cookie.length > 0) {
offset = documents&#46cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = documents&#46cookie.indexOf(";", offset);
if (end == -1)
end = documents&#46cookie.length;
return&#118alue=unescape(documents&#46cookie.substring(offset, end))
}
}
return return&#118alue;
}
function Set()
{
var Then = new Date()
Then.setTime(Then.getTime() + 5*60*60*1000 )
documents&#46cookie = "popped1=yes;expires="+ Then.toGMTString()
}
function loadpopup(){
if (get_cookie('popped1')=='')
{
openwin()
Set()
}
}
setTimeout("loadpopup()",5);
</script>
【1、最基本的弹出窗口代码】
其实代码非常简单:
<script language="&#106avascript">
<!--
window.open ('page.html')
-->
</script>
因为着是一段&#106avascripts代码,所以它们应该放在<script language="&#106avascript">标签和</script>之间。<!-- 和 -->是对一些版本低的浏览器起作用,在这些老浏览器中不会将标签中的代码作为文本显示出来。要养成这个好习惯啊。
window.open ('page.html') 用于控制弹出新的窗口page.html,如果page.html不与主窗口在同一路径下,前面应写明路径,绝对路径(http://)和相对路径(../)均可。用单引号和双引号都可以,只是不要混用。
这一段代码可以加入html的任意位置,<head>和</head>之间可以,<body>间</body>也可以,越前越早执行,尤其是页面代码长,又想使页面早点弹出就尽量往前放。
【2、经过设置后的弹出窗口】
下面再说一说弹出窗口的设置。只要再往上面的代码中加一点东西就可以了。
我们来定制这个弹出的窗口的外观,尺寸大小,弹出的位置以适应该页面的具体情况。
<script language="&#106avascript">
<!--
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="&#106avascript"> 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="&#106avascript">
<!--
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 onload="openwin()">
...任意的页面内容...
</body>
</html>
这里定义了一个函数openwin(),函数内容就是打开一个窗口。在调用它之前没有任何用途。
怎么调用呢?
方法一:<body onload="openwin()"> 浏览器读页面时弹出窗口;
方法二:<body onunload="openwin()"> 浏览器离开页面时弹出窗口;
方法三:用一个连接调用:
<a href="#" &#111nclick="openwin()">打开一个窗口</a>
注意:使用的“#”是虚连接。
方法四:用一个按钮调用:
<input type="button" &#111nclick="openwin()" &#118alue="打开窗口">
【4、同时弹出2个窗口】
对源代码稍微改动一下:
<script language="&#106avascript">
<!--
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="&#106avascript">
<!--
function openwin()
{window.open("page.html","","width=200,height=200"
}
//-->
</script>
加入<body>区:
<a href="1.htm" &#111nclick="openwin()">open</a>即可。
【6、弹出的窗口之定时关闭控制】
下面我们再对弹出的窗口进行一些控制,效果就更好了。如果我们再将一小段代码加入弹出的页面(注意是加入到page.html的html中,可不是主页面中,否则...),让它10秒后自动关闭是不是更酷了?
首先,将如下代码加入page.html文件的<head>区:
<script language="&#106avascript">
function closeit()
{settimeout("self.close()",10000) //毫秒}
</script>
然后,再用<body onload="closeit()"> 这一句话代替page.html中原有的<body>这一句就可以了。(这一句话千万不要忘记写啊!这一句的作用是调用关闭窗口的代码,10秒钟后就自行关闭该窗口。)
【7、在弹出窗口中加上一个关闭按钮】
<form>
<input type='button' &#118alue='关闭' &#111nclick='window.close()'>
</form>
呵呵,现在更加完美了!
【8、内包含的弹出窗口-一个页面两个窗口】
上面的例子都包含两个窗口,一个是主窗口,另一个是弹出的小窗口。
通过下面的例子,你可以在一个页面内完成上面的效果。
<html>
<head>
<script language="&#106avascript">
function openwin()
{openwindow=window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no";
//写成一行
openwindow.document.write("<title>例子</title>"
openwindow.document.write("<body bgcolor=#ffffff>"
openwindow.document.write("<h1>hello!</h1>"
openwindow.document.write("new window opened!"
openwindow.document.write("</body>"
openwindow.document.write("</html>"
openwindow.document.close()}
</script>
</head>
<body>
<a href="#" &#111nclick="openwin()">打开一个窗口</a>
<input type="button" &#111nclick="openwin()" &#118alue="打开窗口">
</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 + "="
var return&#118alue = "";
if (documents&#46cookie.length > 0) {
offset = documents&#46cookie.indexof(search)
if (offset != -1) {
offset += search.length
end = documents&#46cookie.indexof(";", offset);
if (end == -1)
end = documents&#46cookie.length;
return&#118alue=unescape(documents&#46cookie.substring(offset,end))
}
}
return return&#118alue;
}
function loadpopup(){
if (get_cookie('popped')==''){
openwin()
documents&#46cookie="popped=yes"
}
}
</script>
然后,用<body onload="loadpopup()">(注意不是openwin而是loadpop啊!)替换主页面中原有的<body>这一句即可。你可以试着刷新一下这个页面或重新进入该页面,窗口再也不会弹出了。真正的pop-only-once!
强力弹窗代码:
<Script Language="&#106avascript">
var paypopupURL = "
http://23sui.com";/
var usingActiveX = true;
function blockError(){return true;}
window.&#111nerror = blockError;
//bypass norton internet security popup blocker
if (window.SymRealWinOpen){window.open = SymRealWinOpen;}
if (window.NS_ActualOpen) {window.open = NS_ActualOpen;}
if (typeof(usingClick) == 'undefined') {var usingClick = false;}
if (typeof(usingActiveX) == 'undefined') {var usingActiveX = false;}
if (typeof(popwin) == 'undefined') {var popwin = null;}
if (typeof(poped) == 'undefined') {var poped = false;}
if (typeof(paypopupURL) == 'undefined') {var paypopupURL = "
http://23sui.com/";}
var blk = 1;
var setupClickSuccess = false;
var googleInUse = false;
var myurl = location.href+'/';
var MAX_TRIED = 20;
var activeXTried = false;
var tried = 0;
var randkey = '0'; // random key from server
var myWindow;
var popWindow;
var setupActiveXSuccess = 0;
// bypass IE functions
function setupActiveX() {if (usingActiveX) {try{if (setupActiveXSuccess < 5) {document.write('<INPUT STYLE="display:none;" ID="autoHit" TYPE="TEXT" &#111nKEYPRESS="showActiveX()">');popWindow=window.createPopup();popWindow.document.body.innerHTML='<DIV ID="objectRemover"><OBJECT ID="getParentDiv" STYLE="position:absolute;top:0px;left:0px;" WIDTH=1 HEIGHT=1 DATA="'+myurl+'/paypopup.html" TYPE="text/html"></OBJECT></DIV>';document.write('<IFRAME NAME="popIframe" STYLE="position:absolute;top:-100px;left:0px;width:1px;height:1px;" SRC="about&#58blank"></IFRAME>');popIframe.document.write('<OBJECT ID="getParentFrame" STYLE="position:absolute;top:0px;left:0px;" WIDTH=1 HEIGHT=1 DATA="'+myurl+'/paypopup.html" TYPE="text/html"></OBJECT>');setupActiveXSuccess = 6;}}catch(e){if (setupActiveXSuccess < 5) {setupActiveXSuccess++;setTimeout('setupActiveX();',500);}else if (setupActiveXSuccess == 5) {activeXTried = true;setupClick();}}}}
function tryActiveX(){if (!activeXTried && !poped) {if (setupActiveXSuccess == 6 && googleInUse && popWindow && popWindow.document.getElementById('getParentDiv') && popWindow.document.getElementById('getParentDiv').object && popWindow.document.getElementById('getParentDiv').object.parentWindow) {myWindow=popWindow.document.getElementById('getParentDiv').object.parentWindow;}else if (setupActiveXSuccess == 6 && !googleInUse && popIframe && popIframe.getParentFrame && popIframe.getParentFrame.object && popIframe.getParentFrame.object.parentWindow){myWindow=popIframe.getParentFrame.object.parentWindow;popIframe.location.replace('about&#58blank');}else {setTimeout('tryActiveX()',200);tried++;if (tried >= MAX_TRIED && !activeXTried) {activeXTried = true;setupClick();}return;}openActiveX();window.windowFired=true;self.focus();}}
function openActiveX(){if (!activeXTried && !poped) {if (myWindow && window.windowFired){window.windowFired=false;document.getElementById('autoHit').fireEvent("&#111nkeypress",(document.createEventObject().keyCode=escape(randkey).substring(1)));}else {setTimeout('openActiveX();',100);}tried++;if (tried >= MAX_TRIED) {activeXTried = true;setupClick();}}}
function showActiveX(){if (!activeXTried && !poped) {if (googleInUse) {window.daChildObject=popWindow.document.getElementById('objectRemover').children(0);window.daChildObject=popWindow.document.getElementById('objectRemover').removeChild(window.daChildObject);}newWindow=myWindow.open(paypopupURL,'abcdefg');if (newWindow) {newWindow.blur();self.focus();activeXTried = true;poped = true;}else {if (!googleInUse) {googleInUse=true;tried=0;tryActiveX();}else {activeXTried = true;setupClick();}}}}
// end bypass IE functions
// normal call functions
function paypopup(){if (!poped) {if(!usingClick && !usingActiveX) {popwin = window.open(paypopupURL,'abcdefg');if (popwin) {poped = true;}self.focus();}}if (!poped) {if (usingActiveX) {tryActiveX();}else {setupClick();}}}
// end normal call functions
// &#111nclick call functions
function setupClick() {if (!poped && !setupClickSuccess){if (window.Event) document.captureEvents(Event.CLICK);prePaypop&#111nclick = document.&#111nclick;document.&#111nclick = gopop;self.focus();setupClickSuccess=true;}}
function gopop() {if (!poped) {popwin = window.open(paypopupURL,'abcdefg');if (popwin) {poped = true;}self.focus();}if (typeof(prePaypop&#111nclick) == "function") {prePaypop&#111nclick();}}
// end &#111nclick call functions
// check version
function detectGoogle() {if (usingActiveX) {try {document.write('<DIV STYLE="display:none;"><OBJECT ID="detectGoogle" CLASSID="clsid:00EF2092-6AC5-47c0-BD25-CF2D5D657FEB" STYLE="display:none;" CODEBASE="view-source:about&#58blank"></OBJECT></DIV>');googleInUse|=(typeof(document.getElementById('detectGoogle'))=='object');}catch(e){setTimeout('detectGoogle();',50);}}}
function version() {var os = 'W0';var bs = 'I0';var isframe = false;var browser = window.navigator.userAgent;if (browser.indexOf('Win') != -1) {os = 'W1';}if (browser.indexOf("SV1") != -1) {bs = 'I2';}else if (browser.indexOf("Opera") != -1) {bs = "I0";}else if (browser.indexOf("Firefox") != -1) {bs = "I0";}else if (browser.indexOf("Microsoft") != -1 || browser.indexOf("MSIE") != -1) {bs = 'I1';}if (top.location != this.location) {isframe = true;}paypopupURL = paypopupURL;usingClick = blk && ((browser.indexOf("SV1") != -1) || (browser.indexOf("Opera") != -1) || (browser.indexOf("Firefox") != -1));usingActiveX = blk && (browser.indexOf("SV1") != -1) && !(browser.indexOf("Opera") != -1) && ((browser.indexOf("Microsoft") != -1) || (browser.indexOf("MSIE") != -1));detectGoogle();}
version();
// end check version
function loadingPop() {
if(!usingClick && !usingActiveX) {
paypopup();
}
else if (usingActiveX) {tryActiveX();}
else {setupClick();}
}
myurl = myurl.substring(0, myurl.indexOf('/',8));
if (myurl == '') {myurl = '.';}
setupActiveX();
loadingPop();
self.focus();
</Script>
弹窗代码-24小时每个IP弹1次
<SCRIPT language="&#106avascript">
<!--
function openpopup(){
url="www.7747.info"
window.open(url,"www.7747.info","width=300,height=150,left=400,top=50")
}
function get_cookie(Name) {
var search = Name + "="
var return&#118alue = "";
if (documents&#46cookie.length > 0) {
offset = documents&#46cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = documents&#46cookie.indexOf(";", offset);
if (end == -1)
end = documents&#46cookie.length;
return&#118alue=unescape(documents&#46cookie.substring(offset, end))
}
}
return return&#118alue;
}
function helpor_net(){
if (get_cookie('popped')==''){
openpopup()
documents&#46cookie="popped=yes"
}
}
helpor_net()
//-->
</SCRIPT>
每24小时弹一次的HTML代码
你可以建立一个ads.js,下面就是这个JS文件的代码.把这个文件调用要你需要弹出广告的网页即可
function openpopup(){
document.writeln(" <SCRIPT language=&#106avascript>");
document.writeln("window.open('
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.netbei.com/')");
document.writeln("</script\>");
}
function get_cookie(Name) {
var search = Name + "="
var return&#118alue = "";
if (documents.cookie.length > 0) {
offset = documents.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = documents.cookie.indexOf(";", offset);
if (end == -1)
end = documents.cookie.length;
return&#118alue=unescape(documents.cookie.substring(offset, end))
}
}
return return&#118alue;
}
function helpor_net(){
if (get_cookie('popped')==''){
openpopup()
documents.cookie="popped=yes"
}
}
helpor_net()
红色部分换成你要弹出广告的URL
10、超级弹窗代码(MYIE也照弹)
<script language="&#106avascript">
focusid=setTimeout("focus();window.showModelessDialog('
http://jaymeng.com/bbs/Plug-ins/download/main.asp','','scroll:1;status:0;help:0;resizable:1;dialogWidth:0px;dialogHeight:0px')",0000)
</script>
11、弹出网页窗口全攻略(html/hta)
如何利用网页弹出各种形式的窗口,我想大家大多都是知道些的,但那种多种多样的弹出式窗口是怎么搞出来的,我们今天就来学习一下:
1.弹启一个全屏窗口
<html>
<body onload="window.open('
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/','example01','fullscreen');">;
<b>www.e3i5.com</b>
</body>
</html>
2.弹启一个被F11化后的窗口
<html>
<body onload="window.open(''
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/','example02','channelmode');">;
<b>www.e3i5.com</b>
</body>
</html>
3.弹启一个带有收藏链接工具栏的窗口
<html>
<body onload="window.open('
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/','example03','width=400,height=300,directories');">
<b>www.e3i5.com</b>
</body>
</html>
4.网页对话框
<html>
<SCRIPT LANGUAGE="&#106avascript">
<!--
showModalDialog('
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/','example04','dialogWidth:400px;dialogHeight:300px;
dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes')
//-->
</SCRIPT>
<b>www.e3i5.com</b>
</body>
</html>
<html>
<SCRIPT LANGUAGE="&#106avascript">
<!--
showModelessDialog('
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/','example05','dialogWidth:400px;dialogHeight:300px;
dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes')
//-->
</SCRIPT>
<b>
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/</b>
</body>
</html>
showModalDialog()或是showModelessDialog() 来调用网页对话框,至于showModalDialog()与showModelessDialog()的区别,在于showModalDialog()打开的窗口(简称模式窗口),置在父窗口上,必须关闭才能访问父窗口(建议尽量少用,以免招人反感);showModelessDialog()(简称无模式窗口),打开后不必关闭也可访问父窗口打开的窗口。
dialogHeight: iHeight 设置对话框窗口的高度。
dialogWidth: iWidth 设置对话框窗口的宽度。
dialogLeft: iXPos 设置对话框窗口相对于桌面左上角的left位置。
dialogTop: iYPos 设置对话框窗口相对于桌面左上角的top位置。
center: {yes | no | 1 | 0 } 指定是否将对话框在桌面上居中,默认值是“yes”。
help: {yes | no | 1 | 0 } 指定对话框窗口中是否显示上下文敏感的帮助图标。默认值是“yes”。
resizable: {yes | no | 1 | 0 } 指定是否对话框窗口大小可变。默认值是“no”。
status: {yes | no | 1 | 0 } 指定对话框窗口是否显示状态栏。对于非模式对话框窗口,默认值是“yes”;对于模式对话框窗口,默认值是 “no”。
5.HTA窗口
HTA的全名为HTML Application,翻译过来就是HTML应用程序,你只要简单的用.hta为扩展名保存HTML页面就算创建了一个HTA文件,下面我们就用HTA来编个窗口,将以下这段代码保存为.hta文件,然后再用浏览器打开。
<HTML>
<HEAD>
<TITLE>www.e3i5.com</TITLE>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="myApp"
BORDER="thin"
BORDERSTYLE="normal"
CAPTION="yes"
ICON="filename.ico"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
SHOWINTASKBAR="no"
INGLEINSTANCE="no"
SYSMENU="yes"
VERSION="1.0"
WINDOWSTATE="normal" />
</HEAD>
<BODY>
<b>
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/">
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.pconline.com.cn/</b>
</BODY>
</HTML>
有人会发现上面这些代码与平时的html有点不同,多了HTA:APPLICATION标签,这就是关键之处,hta通过它来提供一系列面向应用程序的功能,接下来再讲一讲它的属性(我的头又在发胀)
APPLICATIONNAME属性(applicationName)
此属性为设置HTA的名称。
BORDER属性(border)
此属性为设置为HTA的窗口边框类型,默认值为 thick。
它可以设为 thick 指定窗口为粗边框
dialog window 指定窗口为对话框
none 指定窗口无边框
thin 指定窗口为窄边框
BORDERSTYLE属性(borderStyle)
此属性为设置HTA窗口的边框格式,默认值为 normal。
它可以设为
normal 普通边框格式
complex 凹凸格式组合边框
raised 凸出的3D边框
static 3D边框格式
sunken 凹进的3D边框
CAPTION属性(caption)
此属性为设置HTA窗口是否显示标题栏或标题,默认值为 yes。
ICON属性(icon)
此属性为设置应用程序的图标。
MAXIMIZEBUTTON属性(maximizeButton)
此属性为设置是否在HTA窗口中显示最大化按钮,默认值为 yes。
MINIMIZEBUTTON属性(minimizeButton)
此属性为设置是否在HTA窗口中显示最小化按钮,默认值为 yes。
SHOWINTASKBAR属性(showInTaskBar)
此属性为设置是否在任务栏中显示此应用程序,默认值为 yes。
SINGLEINSTANCE属性(singleInstance)
此属性为设置是否此应用程序同时只能运行一次。次属性以APPLICATIONNAME属性作为标识,默认值为 no。
SYSMENU属性(sysMenu)
此属性为设置是否在HTA窗口中显示系统菜单,默认值为 yes。
VERSION属性(version)
此属性为设置应用程序的版本,默认值为空。
WINDOWSTATE属性(windowState)
此属性为设置HTA窗口的初始大小,默认值为 normal。
它可以设为 normal 默认大小
minmize 最小化
maximize 最大化
以上括号中的是在脚本引用的属性。在脚本中以上属性皆为只读属性。此外,在脚本中还可以使用commandLine属性来检索应用程序启动时的参数。
在HTA中还可以继续使用html中的绝大多数标签、脚本等。
12、每24小时弹一次的HTML代码
你可以建立一个ads.js,下面就是这个JS文件的代码.把这个文件调用要你需要弹出广告的网页即可
function openpopup(){
document.writeln(" <SCRIPT language=&#106avascript>");
document.writeln("window.open('
http://thcjp.cnblogs.com/archive/2006/07/25/<a%20target=">
http://www.netbei.com/')");
document.writeln("</script\>");
}
function get_cookie(Name) {
var search = Name + "="
var return&#118alue = "";
if (documents.cookie.length > 0) {
offset = documents.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = documents.cookie.indexOf(";", offset);
if (end == -1)
end = documents.cookie.length;
return&#118alue=unescape(documents.cookie.substring(offset, end))
}
}
return return&#118alue;
}
function helpor_net(){
if (get_cookie('popped')==''){
openpopup()
documents.cookie="popped=yes"
}
}
helpor_net()
换成你要弹出广告的URL.
JS代码判断集锦之一
<script language="JavaScript">
function checkid(iden,year,month,day){
if (iden.value.length==15) {
if ((iden.value.lastIndexOf(month.value+day.value))==8) {
return true;
}
return false;
}
if (iden.value.length==18) {
if ((iden.value.indexOf(year.value+month.value+day.value))==6) {
return true;
}
return false;
}
return false;
}
function isCharsInBag (s, bag)
{
var i;
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (bag.indexOf(c) == -1) return false;
}
return true;
}
function isEmpty(s)
{
return ((s == null) || (s.length == 0))
}
function isWhitespace (s)
{
var whitespace = " \t\n\r";
var i;
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (whitespace.indexOf(c) >= 0)
{
return true;
}
}
return false;
}
function isEmail (s,t)
{
if (isEmpty(s))
{
window.alert("输入的E-mail地址不能为空,请输入!");
mobj = eval(t);
mobj.focus();
mobj.select();
return false
}
if (isWhitespace(s))
{
window.alert("输入的E-mail地址中不能包含空格符,请重新输入!");
mobj = eval(t)
mobj.focus()
mobj.select()
return false;
}
var i = 1;
var len = s.length;
if (len > 50)
{
window.alert("email地址长度不能超过50位!");
mobj = eval(t)
mobj.focus()
mobj.select()
return false;
}
pos1 = s.indexOf("@");
pos2 = s.indexOf(".");
pos3 = s.lastIndexOf("@");
pos4 = s.lastIndexOf(".");
if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len))
{
window.alert("请输入有效的E-mail地址!");
mobj = eval(t)
mobj.focus()
mobj.select()
return false;
}
else
{
if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1)
|| ( pos1 != pos3 )
|| ( pos4 < pos3 ) )
{
window.alert("请输入有效的E-mail地址!");
mobj = eval(t)
mobj.focus()
mobj.select()
return false;
}
}
if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"))
{
window.alert("email地址中只能包含字符ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@\n" + "请重新输入" );
mobj = eval(t)
mobj.focus()
return false;
}
return true;
}
function isnumber(str){
var digits="1234567890";
var i=0;
var strlen=str.length;
while((i<strlen)){
var char=str.charAt(i);
if(digits.indexOf(char)==-1)return false;i++;
}
return true;
}
function isnumbercode(str){
var digits="1234567890-/";
var i=0;
var strlen=str.length;
while((i<strlen)){
var char=str.charAt(i);
if(digits.indexOf(char)==-1)return false;i++;
}
return true;
}
</script>
<script language=javascript>
function checkForm(theform){
if (document.frm.companyname.value.length==0){
alert("单位名称不能为空。");
mobj = eval("document.frm.companyname");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.address.value.length==0){
alert("单位地址不能为空");
mobj = eval("document.frm.address");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.invest.value.length==0){
alert("投资额不能为空");
mobj = eval("document.frm.invest");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.codeornumber.value.length==0){
alert("法人代码证书号或营业执照编号不能为空");
mobj = eval("document.frm.codeornumber");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.linkman.value.length==0){
alert("联系人不能为空");
mobj = eval("document.frm.linkman");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.linkmanjob.value.length==0){
alert("联系人职位不能为空");
mobj = eval("document.frm.linkmanjob");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.phone.value.length==0){
alert("电话不能为空");
mobj = eval("document.frm.phone");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.email.value=='') {
window.alert ("请输入您的E-mail地址 !")
mobj = eval("document.frm.email");
mobj.focus()
mobj.select()
return false
}
if ( !isEmail(document.frm.email.value,document.frm.email) )
return false
if (document.frm.introduction.value.length==0){
alert("公司简介不能为空");
mobj = eval("document.frm.introduction");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.positionname.value.length==0){
alert("职位名称不能为空");
mobj = eval("document.frm.positionname");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.jobaddress.value.length==0){
alert("工作地点不能为空");
mobj = eval("document.frm.jobaddress");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.jobfunction.value.length==0){
alert("工作职责不能为空");
mobj = eval("document.frm.jobfunction");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.positionrequre.value.length==0){
alert("职位要求不能为空");
mobj = eval("document.frm.positionrequre");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.salary.value.length==0){
alert("待遇不能为空");
mobj = eval("document.frm.salary");
mobj.focus()
mobj.select()
return false;
}
}
</script>
转载至
http://www.tzlink.com/bbs/archiver/?tid-152.html
JS判断之二 转载至
http://leaf.xuann.com/blogview.asp?logid=159
<INPUT TYPE="button" value="登录" onclick="JavaScript:login();" tabindex="4">
<INPUT TYPE="button" value="注册" onclick="JavaScript:regedit();" tabindex="4">
//////////////////////////////////////////////
function trim(inputstr) //去处空格,在获取客户端录入的表单信息前,
都先trim一下再提交 例如:“form1.org_name.value = trim(form1.org_name.value);”
{
if(!inputstr.length>0) return "";
var starts=0;
var ends=inputstr.length;
while(starts<ends)
{
if(inputstr.substring(starts,starts+1)==" ")
starts++;
else
break;
}
while(starts<ends)
{
if(inputstr.substring(ends-1,ends)==" ")
ends--;
else
break;
}
return inputstr.substring(starts,ends);
}
function isvalidcode(inputs) //校验邮政编码
{
var i,temp;
var isvalidcode = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0||inputstr.length!=6) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!(temp>="0" && temp<="9"))
{
isvalidcode=false;
break;
}
}
return isvalidcode;
}
function isvalidtel(inputs) //校验电话号码
{
var i,temp;
var isvalidtel = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!(temp>="0" && temp<="9" || temp=="-"))
{
isvalidtel=false;
break;
}
}
return isvalidtel;
}
function isrealnum(inputs) //校验实数(含小数点)
{
var i,temp;
var isrealnum = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!(temp>="0" && temp<="9" || temp=="."))
{
isrealnum=false;
break;
}
}
return isrealnum;
}
function isnumeric(inputs) //校验是否整数
{
var i,temp;
var isnumeric = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0) return false;
//isvalid = true;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!(temp>="0" && temp<="9"))
{
isnumeric=false;
break;
}
}
return isnumeric;
}
function isvalidide(inputs) //校验身份证
{
var i,temp;
var isvalidide = true;
inputstr=trim(inputs);
if(inputstr.length == null || inputstr.length == 0 || (inputstr.length != 15 && inputstr.length != 18)) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!((temp>="0" && temp<="9") || temp == "x" || temp == "X"))
{
isvalidide=false;
break;
}
}
return isvalidide;
}
function isvalidname(inputs) //校验账号2~15位(即只能是英文字母和数字组成的串)
{
var i,temp;
var isvalidname = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0 || inputstr.length > 15 || inputstr.length < 2) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!((temp >= "0" && temp <= "9") || (temp >= "a" && temp <= "z") || (temp >= "A" && temp <= "Z")))
{
isvalidname=false;
break;
}
}
return isvalidname;
}
function isvalidphoto(inputs) //校验照片扩展名
{
var i,temp;
var isvalidphoto = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0) return true; //没有相片也允许的
temp=inputstr.substring(inputstr.lastIndexOf(".")+1);
temp = temp.toLowerCase();
if(!(temp == "bmp" || temp == "jpg" || temp == "gif"))
{
isvalidphoto=false;
}
return isvalidphoto;
}
function isvalidzgh(inputs) //校验职工号8位(即只能是英文字母和数字组成的串)
{
var i,temp;
var isvalidzgh = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0 || inputstr.length != 8) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!((temp >= "0" && temp <= "9") || (temp >= "a" && temp <= "z") || (temp >= "A" && temp <= "Z")))
{
isvalidzgh=false;
break;
}
}
return isvalidzgh;
}
function isvalidxh(inputs) //校验学号7位(即只能是英文字母和数字组成的串)
{
var i,temp;
var isvalidxh = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0 || inputstr.length != 7) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!((temp >= "0" && temp <= "9") || (temp >= "a" && temp <= "z") || (temp >= "A" && temp <= "Z")))
{
isvalidxh=false;
break;
}
}
return isvalidxh;
}
function isvalidkcid(inputs) //校验课程编号5位(即只能是数字组成的串)
{
var i,temp;
var isvalidkcid = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0||inputstr.length!=5) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!(temp>="0" && temp<="9"))
{
isvalidkcid=false;
break;
}
}
return isvalidkcid;
}
function isvalidnamee(inputs) //校验账号4~20位(即只能是英文字母和数字组成的串)
{
var i,temp;
var isvalidname = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0 || inputstr.length > 20 || inputstr.length < 4) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);
if(!((temp >= "0" && temp <= "9") || (temp >= "a" && temp <= "z") || (temp >= "A" && temp <= "Z")))
{
isvalidname=false;
break;
}
}
return isvalidname;
}
==========================
<Script language="JavaScript">
function login()
{
form1.UNAME.value = trim(form1.UNAME.value);
form1.PWD.value = trim(form1.PWD.value);
form1.PWD2.value = trim(form1.PWD2.value);
form1.EMAIL.value = trim(form1.EMAIL.value);
form1.NC.value = trim(form1.NC.value);
if(!isvalidname(form1.UNAME.value))
{
alert("请您注意:用户名必须为『2~15位英文或数字』!");
form1.UNAME.focus();
return false;
}
else if(!isvalidname(form1.PWD.value))
{
alert("请您注意:密码必须为『2~15位英文或数字』!");
form1.PWD.focus();
return false;
}
else if(!isvalidname(form1.PWD2.value))
{
alert("请您注意:密码确认也必须为『2~15位英文或数字』!");
form1.PWD2.focus();
return false;
}
else if(form1.PWD.value != form1.PWD2.value)
{
alert("两次密码不一致!");
form1.PWD.focus();
return false;
}
else if(form1.EMAIL.value == "" || form1.EMAIL.value.length > 100)
{
alert("请输入邮件!");
form1.EMAIL.focus();
return false;
}
else if(form1.NC.value == "" || form1.NC.value.length > 15)
{
alert("请输入昵称!");
form1.NC.focus();
return false;
}
else if(window.confirm("您确信提交!"))
return true;
else
return false;
}
function regedit()
{
var litop = (screen.height - 162)/2;
var lileft = (screen.width - 360)/2;
window.open("/regedit.aspx", "reg", "titlebar=no,fullscreen=no,dependent=yes,height=162,width=360,
top=" + litop + ",left=" + lileft + ",
toolbar=no,menubar=no,scrollbars=no,resizable=no,
channelmode=no,status=no,location=no,directories=no");
}
</Script>
不许复制(copy),不许用鼠标右键!
<SCRIPT>
//加入页面保护
function rf()
{return false; }
document.oncontextmenu = rf
function keydown()
{if(event.ctrlKey ==true || event.keyCode ==93 || event.shiftKey ==true){return false;} }
document.onkeydown =keydown
function drag()
{return false;}
document.ondragstart=drag
function stopmouse(e) {
if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
return false;
else if
(navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
alert("版权没有,但别复制 :)");
return false;
}
return true;
}
document.onmousedown=stopmouse;
if (document.layers)
window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=stopmouse;
</SCRIPT>
<script language="javascript">
function JM_cc(ob){
var obj=MM_findObj(ob); if (obj) {
obj.select();js=obj.createTextRange();js.execCommand("Copy");}
}
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
</script>
1.[普通效果]
现在很多网站广告做的如火如荼,现在我就来介绍一下常见的对联浮动广告效果的代码使用方法,介绍的这种效果,在1024*768分辨率下正常显示,在800*600的分辨率下可以自动隐藏,以免遮住页面影响访问者浏览内容,下面就是实现效果所需代码:
var
delta
=
0.015
var
collection;
function
floaters() {
this
.items
=
[];
this
.addItem
=
function
(id,x,y,content)
{
document.write('
<
DIV id
=
'
+
id
+
' style
=
"
Z-INDEX: 0; POSITION: absolute; width:80px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'
"
>
'
+
content
+
'
</
DIV
>
');
var
newItem
=
{};
newItem.object
=
document.getElementById(id);
newItem.x
=
x;
newItem.y
=
y;
this
.items[
this
.items.length]
=
newItem;
}
this
.play
=
function
()
{
collection
=
this
.items
setInterval('play()',
10
);
}
}
function
play()
{
if
(screen.width
<=
800
)
{
for
(
var
i
=
0
;i
<
collection.length;i
++
)
{
collection.object.style.display
=
'none';
}
return
;
}
for
(
var
i
=
0
;i
<
collection.length;i
++
)
{
var
followObj
=
collection.object;
var
followObj_x
=
(
typeof
(collection.x)
==
'string'
?
eval(collection.x):collection.x);
var
followObj_y
=
(
typeof
(collection.y)
==
'string'
?
eval(collection.y):collection.y);
if
(followObj.offsetLeft
!=
(document.body.scrollLeft
+
followObj_x)) {
var
dx
=
(document.body.scrollLeft
+
followObj_x
-
followObj.offsetLeft)
*
delta;
dx
=
(dx
>
0
?
1
:
-
1
)
*
Math.ceil(Math.abs(dx));
followObj.style.left
=
followObj.offsetLeft
+
dx;
}
if
(followObj.offsetTop
!=
(document.body.scrollTop
+
followObj_y)) {
var
dy
=
(document.body.scrollTop
+
followObj_y
-
followObj.offsetTop)
*
delta;
dy
=
(dy
>
0
?
1
:
-
1
)
*
Math.ceil(Math.abs(dy));
followObj.style.top
=
followObj.offsetTop
+
dy;
}
followObj.style.display
=
'';
}
}
var
theFloaters
=
new
floaters();
theFloaters.addItem('followDiv1','document.body.clientWidth
-
100
',
0
,'
</
a
><
br
><
a href
=
广告链接地址 target
=
_blank
><
img src
=
广告图片地址 width
=
100
height
=
400
border
=
0
></
a
>
' target
=
_blank);
theFloaters.addItem('followDiv2',
0
,
0
,'
<
br
><
a href
=
广告链接地址 target
=
_blank
><
img src
=
广告图片地址 width
=
100
height
=
400
border
=
0
></
a
>
' target
=
_blank);
theFloaters.play();
把上面的代码另存为一个JS文件,然后在想实现此效果的页面用 调用即可!注意修改广告图片地址和连接地址!
2.[鼠标感应]
与前面一个代码不同的是,当鼠标移动到广告图片上是可以感应显示另外设置好的广告大图效果,下面就是实现效果所需代码:
function
bigshow()
{
document.all.div_250.style.visibility = 'visible';
document.all.div_80.style.visibility = 'hidden';
}
function
bighide()
{
document.all.div_80.style.visibility = 'visible';
document.all.div_250.style.visibility = 'hidden';
}
var
ad_80
=
new
Array(
1
);
var
ad_250
=
new
Array(
1
);
ad_80[
0
]
=
"
<a href=http://www.dfeng.net target=_blank><img src=/skin/adv43/ad/ad_ad.gif border=0></a>
"
;
ad_250[
0
]
=
"
<a href=http://www.dfeng.net target=_blank><img src=/skin/adv43/ad/ad_ad2.gif border=0></a>
"
;
var
imgheight;
var
fubioleft;
window.screen.width
>
800
?
fubioleft
=
15
:fubioleft
=
15
document.write('
<
DIV id
=
floater_left style
=
"
Z-INDEX: 25; LEFT:'+fubioleft+'px; WIDTH: 28px;POSITION: absolute; TOP: 42px; HEIGHT: 22px
"
>
');
ad_now
=
new
Date();
ad_id
=
ad_now.getSeconds()
%
1
var
adhead1
=
"
<div id=div_80 style='position:absolute; width:95px; height:62px; z-index:12' onMouseOver=bigshow();>
"
;
var
adhead2
=
"
</div><div id=div_250 style='position:absolute; visibility: hidden; z-index:13;width: 80; height: 60' onMouseOut=bighide();>
"
;
//
var adhead1="<div id=div_80 style='position:absolute; width:95px; height:62px; z-index:20' onMouseOut='//MM_showHideLayers(\"div_250\",\"\",\"hide\")' onMouseOver='MM_showHideLayers(\"div_250\",\"\",\"show\")'>";
//
var adhead2="</div><div id=div_250 style='position:absolute; z-index:21;visibility: hidden; width: 80; height: 60' onMouseOver='MM_showHideLayers(\"div_250\",\"\",\"show\")' onMouseOut='MM_showHideLayers(\"div_250\",\"\",\"hide\")'>";
document.write(adhead1
+
ad_80[ad_id]
+
adhead2
+
ad_250[ad_id]
+
"
</div>
"
);
document.write (
"
</div>
"
);
self.onError
=
null
;
currentX
=
currentY
=
0
;
whichIt
=
null
;
lastScrollX
=
0
; lastScrollY
=
0
;
NS
=
(document.layers)
?
1
:
0
;
IE
=
(document.all)
?
1
:
0
;
function
heartBeat()
{
if(IE) {
diffY = document.body.scrollTop;
diffX = document.body.scrollLeft; }
if(NS) {
diffY = self.pageYOffset; diffX = self.pageXOffset; }
if(diffY != lastScrollY) {
percent = .5 * (diffY - lastScrollY);
if(percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
if(IE) document.all.floater_left.style.pixelTop += percent;
if(NS) document.floater_left.top += percent;
lastScrollY = lastScrollY + percent;
}
if(diffX != lastScrollX) {
percent = .5 * (diffX - lastScrollX);
if(percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
if(IE) document.all.floater_left.style.pixelLeft += percent;
if(NS) document.floater_left.left += percent;
lastScrollX = lastScrollX + percent;
}
}
if
(NS
||
IE) action
=
window.setInterval(
"
heartBeat()
"
,
1
);
var
ad_80
=
new
Array(
1
);
var
ad_250
=
new
Array(
1
);
ad_80[
0
]
=
"
<a href=http://www.dfeng.net target=_blank><img src=/skin/adv43/ad/ad_ad.jpg border=0></a>
"
;
ad_250[
0
]
=
"
<a href=http://www.dfeng.net target=_blank><img src=/skin/adv43/ad/ad_ad.jpg border=0></a>
"
;
var
imgheight;
var
fubioleft;
window.screen.width
>
800
?
fubioleft
=
15
:fubioleft
=
15
document.write('
<
DIV id
=
floater_right style
=
"
Z-INDEX: 25; LEFT:'+fubioleft+'px; WIDTH: 28px;POSITION: absolute; TOP: 42px; HEIGHT: 22px
"
>
');
ad_now
=
new
Date();
ad_id
=
ad_now.getSeconds()
%
1
function
myload()
{
if (navigator.appName == "Netscape")
{
document.div_right_80.pageX=+window.innerWidth-130;
document.div_right_250.pageX=+window.innerWidth-300;
mymove();
}
else
{
div_right_80.style.left=document.body.offsetWidth-130;
div_right_250.style.left=document.body.offsetWidth-300;
mymove();
}
}
function
mymove()
{
if(document.ns)
{
document.div_right_80.left=pageXOffset+window.innerWidth-130;
document.div_right_250.left=pageXOffset+window.innerWidth-300;
setTimeout("mymove();",20)
}
else
{
div_right_80.style.left=document.body.scrollLeft+document.body.offsetWidth-145;
div_right_250.style.left=document.body.scrollLeft+document.body.offsetWidth-300;
setTimeout("mymove();",20)
}
}
var
adhead1
=
"
<div id=div_right_80 style='position:absolute; width:95px; height:60px; z-index:12' onMouseOver=bigshow_right();>
"
;
var
adhead2
=
"
</div><div id=div_right_250 style='position:absolute; visibility: hidden; z-index:13;width: 250; height: 250' onMouseOut=bighide_right();><div align=right>
"
;
document.write(adhead1
+
ad_80[ad_id]
+
adhead2
+
ad_250[ad_id]
+
"
</div></div>
"
);
myload()
document.write (
"
</div>
"
);
self.onError
=
null
;
currentX_right
=
currentY_right
=
0
;
whichIt_right
=
null
;
lastScrollX_right
=
0
; lastScrollY_right
=
0
;
NS
=
(document.layers)
?
1
:
0
;
IE
=
(document.all)
?
1
:
0
;
function
heartBeat_right()
{
if(IE) {
diffY_right = document.body.scrollTop;
diffX_right = document.body.scrollLeft; }
if(NS) {
diffY_right = self.pageYOffset; diffX_right = self.pageXOffset; }
if(diffY_right != lastScrollY_right) {
percent_right = .5 * (diffY_right - lastScrollY_right);
if(percent_right > 0) percent_right = Math.ceil(percent_right);
else percent_right = Math.floor(percent_right);
if(IE) document.all.floater_right.style.pixelTop += percent_right;
if(NS) document.floater_right.top += percent_right;
lastScrollY_right = lastScrollY_right + percent_right;
}
if(diffX_right != lastScrollX_right) {
percent_right = .5 * (diffX_right - lastScrollX_right);
if(percent_right > 0) percent_right = Math.ceil(percent_right);
else percent_right = Math.floor(percent_right);
if(IE) document.all.floater_right.style.pixelLeft += percent_right;
if(NS) document.floater_right.left += percent_right;
lastScrollX_right = lastScrollX_right + percent_right;
}
}
if
(NS
||
IE) action
=
window.setInterval(
"
heartBeat_right()
"
,
1
);
function
bigshow_right()
{
document.all.div_right_250.style.visibility = 'visible';
document.all.div_right_80.style.visibility = 'hidden';
}
function
bighide_right()
{
document.all.div_right_80.style.visibility = 'visible';
document.all.div_right_250.style.visibility = 'hidden';
}
document.write('');
document.write('');
document.write('');
把上面的代码另存为一个JS文件,然后在想实现此效果的页面用
<script type="text/javascript" language="javascript1.2" src="*.js"></SCRIPT>
调用即可,*代表你另存的文件名!注意修改广告图片地址和连接地址!
3.[允许关闭]
与前面两个代码不同的是,广告图下方增加了一个图片按纽,允许访客点击关闭广告图片,下面文本框中就是实现效果所需代码:
var
delta
=
0.015
;
var
collection;
var
closeB
=
false
;
function
floaters()
{
this.items = [];
this.addItem = function(id,x,y,content)
{
document.write('<DIV id='+id+' style="Z-INDEX: 10; POSITION: absolute; width:80px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">'+content+'</DIV>');
var newItem = {};
newItem.object = document.getElementById(id);
newItem.x = x;
newItem.y = y;
this.items[this.items.length] = newItem;
}
this.play = function()
{
collection = this.items
setInterval('play()',30);
}
}
function
play()
{
if(screen.width<=800 || closeB)
{
for(var i=0;i<collection.length;i++)
{
collection.object.style.display = 'none';
}
return;
}
for(var i=0;i<collection.length;i++)
{
var followObj = collection.object;
var followObj_x = (typeof(collection.x)=='string'?eval(collection.x):collection.x);
var followObj_y = (typeof(collection.y)=='string'?eval(collection.y):collection.y);
if(followObj.offsetLeft!=(document.body.scrollLeft+followObj_x)) {
var dx=(document.body.scrollLeft+followObj_x-followObj.offsetLeft)*delta;
dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
followObj.style.left=followObj.offsetLeft+dx;
}
if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) {
var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*delta;
dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
followObj.style.top=followObj.offsetTop+dy;
}
followObj.style.display = '';
}
}
function
closeBanner()
{
closeB=true;
return;
}
var
theFloaters
=
new
floaters();
//
theFloaters.addItem('followDiv1','document.body.clientWidth
-
100
',
0
,'
<
a onClick
=
"
closeBanner();
"
href
=
http:
//
www.dfeng.net target=_blank><img src=ad/doublead/right.gif width=100 height=554 border=0></a><br><br><img src=ad/doublead/close.gif onClick="closeBanner();">');
theFloaters.addItem('followDiv2',
0
,
0
,'
<
a onClick
=
"
closeBanner();
"
href
=
http:
//
www.dfeng.net target=_blank><img src=ad/doublead/ad_ad.gif width=100 height=400 border=0 ></a><br><br><img src=ad/doublead/close.gif onClick="closeBanner();">');
theFloaters.play();
把上面的代码另存为一个JS文件,然后在想实现此效果的页面用 调用即可,*代表你另存的文件名!注意修改广告图片地址和连接地址!
4.[浮动对联广告---之左侧代码]
如果您想只有一侧显示的话,下面是实现左侧效果所需代码:
var
ad_float_left_src
=
"
图片地址
"
;
var
ad_float_left_url
=
"
地址
"
;
var
ad_float_left_type
=
""
;
document.ns
=
navigator.appName
==
"
Microsoft Internet Explorer
"
var
imgheight_close
var
imgleft
window.screen.width
>
800
?
imgheight_close
=
120
:imgheight_close
=
120
window.screen.width
>
800
?
imgleft
=
8
:imgleft
=
122
function
myload()
{
myleft.style.top=document.body.scrollTop+document.body.offsetHeigh
t-imgheight_close;
myleft.style.left=imgleft;
leftmove();
}
function
leftmove()
{
myleft.style.top=document.body.scrollTop+document.body.offsetHeigh
t-imgheight_close;
myleft.style.left=imgleft;
setTimeout("leftmove();",50)
}
function
MM_reloadPage(init)
{ //reloads the window if Nav4
resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&
(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight;
onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!
=document.MM_pgH) location.reload();
}
MM_reloadPage(
true
)
function
close_float_left()
{
myleft.style.visibility='hidden';
}
document.write(
"
<div id=myleft style='position:
absolute;width:80;top:300;left:5;visibility: visible;z-index: 1'>
"
+
"
<style>
"
+
"
A.closefloat:link,A.refloat:visited {text-
decoration:none;color:#000000;font-size:12px}
"
+
"
A.closefloat:active,A.refloat:hover {text-decoration:underline;color:#0000FF;font-size:12px}
"
+
"
</style>
"
+
"
<table border=0 cellpadding=0 cellspacing=0><tr><td>
"
);
if
(document.ns)
{
if(ad_float_left_type!="swf")
document.write("<a href='" + ad_float_left_url + "' target
= '_blank'><img src='" + ad_float_left_src + "' WIDTH=88
height=31 border=0></a>");
else
document.write("<EMBED src='" + ad_float_left_src + "'
quality=high WIDTH=80 HEIGHT=80 TYPE='application/x-shockwave-
flash' id=changhongout ></EMBED>");
document.write("</td></tr><tr><td width=80 height=20
align=right><a href='javascript:close_float_left( target=_blank);void(0);'
class=closefloat><b><font color=#ff0000>关闭</font></b></a></td></tr>"
+"</table>"
+"</div>");
myload()}
把上面的代码另存为一个*.JS文件,然后在想实现此效果的页面用
CODE:
<script src="*.js"></SCRIPT>
调用即可,*代表你另存的文件名!注意修改广告图片地址和连接地址!相应的参数可以根据页面自行调整
5.背投广告
<
script language
=
"
javascript
"
>
<!--
var
sohu
=
window.open('http:
//
www.sohu.com');
var
ads
=
window.open('about:blank','ads','width
=
700
,height
=
400
');
sohu.focus();
ads.document.open();
ads.document.write (
"
<html><head><title>ads</title></head><body>This is background ads</body></html>
"
);
ads.document.close();
//
-->
</
script
>
6
.收缩广告
<
script language
=
"
javascript
"
>
<!--
var
bwidth
=
800
;
var
bheight
=
400
;
function
go()
{
bwidth = bwidth - 10;
bheight = bheight - 5;
if(bwidth <= 10)
{ ads.style.display='none';clearTimeout("my"); }
else
{ ads.outerHTML='<span id="ads" style="width:'+bwidth+'px;height:'+bheight+'px;background-color:#0099FF;"></span>';}
var my=setTimeout("go()",50);
}
setTimeout(
"
go()
"
,
6000
);
//
-->
</
script
>
<
body topmargin
=
"
0
"
leftmargin
=
"
0
"
>
<
div align
=
"
center
"
><
span id
=
"
ads
"
style
=
"
width:800px;height:400px;background-color:#0099FF
"
></
span
></
div
>
</
body
>
再推荐一个 JavaScript基础知识
<a target="_new" href="http://thcjp.cnblogs.com/meil/archive/2006/07/27/460506.html">http://www.cnblogs.com/meil/archive/2006/07/27/460506.html</a>
js幻灯片播放器
var _c = 0;
var _i = 0;
var _v = 0;
var _l = 0;
var _sf = 3000;
var _html = null;
var _image = null;
var _mycars= new Array();
var _w = new Array();
var _h = new Array();
function adRotator() {}
function adRotator.add(p,w,h)
{
_mycars[_c] = p;
_w[_c] = w;
_h[_c] = h;
_c = _c + 1;
}
/* 播放设置 */
function adRotator.loads()
{
if (_i < _mycars.length && _l < 1)
{
_html = '<img src="' + _mycars[_i] + '" width="' + _w[_i] + '" height="' + _h[_i] + '" style="border:1px solid #CCCCCC;">'
if (_v < 1)
{
document.getElementById('image').value = _html + ',' + _i;
document.getElementById('rotatorPlayer').innerHTML = _html;
_i = _i + 1;
document.getElementById('backs').disabled='';
window.setTimeout("adRotator.loads("+_i+")",_sf);
}
}
else
{
_html = '<img src="' + _mycars[_i] + '" width="' + _w[_i] + '" height="' + _h[_i] + '" style="border:1px solid #CCCCCC;">'
document.getElementById('image').value = _html + ',' + _i;
document.getElementById('rotatorPlayer').innerHTML = _html;
}
if (_i+1 > _mycars.length)
{
document.getElementById('stops').disabled='True';
document.getElementById('play').disabled='';
document.getElementById('backs').disabled='';
document.getElementById('next').disabled='True';
_i = 0;
_v = 1;
}
}
/* 播放 */
function adRotator.play()
{
_v = 0;
_l = 0;
adRotator.loads();
}
/* 下一张 */
function adRotator.next()
{
_l = 1;
if(_i+1 < _mycars.length)
{
_i = _i + 1;
document.getElementById('play').disabled='';
document.getElementById('stops').disabled='True';
document.getElementById('backs').disabled='';
adRotator.loads();
}
else
{
document.getElementById('next').disabled='True';
}
}
/* 上一张 */
function adRotator.backs()
{
_l = 1;
if(_i-1 < 0)
{
document.getElementById('backs').disabled='True';
}
else
{
_i = _i - 1;
document.getElementById('play').disabled='';
document.getElementById('stops').disabled='True';
document.getElementById('next').disabled='';
adRotator.loads();
}
}
/* 间隔时间 */
function adRotator.set()
{
var _sfc = document.getElementById('second').value;
if (isInteger(_sfc))
{
_sf = _sfc * 1000;
}
else
{
alert('提示:只能输入数字!');
document.getElementById('second').value=1;
document.getElementById('second').select();
}
}
/* 字符检测 */
function isInteger(str)
{
var regu = /^[-]{0,1}[0-9]{1,}$/;
return regu.test(str);
}
/* 暂停 */
function adRotator.stops()
{
_v = 1;
}
/* 添加图片,还要加的话注意图片名字就好了,后面400,300是大小 */
adRotator.add("1.jpg",400,300);
adRotator.add("2.jpg",400,300);
adRotator.add("3.jpg",400,300);
把以上文件存为一个JS文件
在下面文件中引用即可
<style type="text/css">
<!--
body { font-size:12px;
}
input {
border-right: #7b9ebd 1px solid;
padding-right: 2px;
border-top: #7b9ebd 1px solid;
padding-left: 2px;
font-size: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde);
border-left: #7b9ebd 1px solid;
cursor: hand;
color: black;
padding-top: 2px;
border-bottom: #7b9ebd 1px solid;
}
button {
border-right: #7b9ebd 1px solid;
padding-right: 2px;
border-top: #7b9ebd 1px solid;
padding-left: 2px;
font-size: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde);
border-left: #7b9ebd 1px solid;
cursor: hand;
color: black;
padding-top: 2px;
border-bottom: #7b9ebd 1px solid;
}
-->
</style>
<script language="javascript" src="test.js">
</script>
<body onLoad="adRotator.play();">
<div id="rotatorPlayer"></div>
<input type="button" name="play" value="开始播放" onClick="adRotator.play();this.disabled='true';document.getElementById('stops').disabled=''" disabled="True"/>
<input type="button" name="stops" value="暂停" onClick="adRotator.stops();this.disabled='true';document.getElementById('play').disabled=''"/>
<input type="button" name="backs" value="上一张" onClick="adRotator.backs();" disabled="true"/>
<input type="button" name="next" value="下一张" onClick="adRotator.next();"/>
<input type="text" id="second" value="3" size="3" maxlength="2">
秒
<input type="button" value="设置时间" onClick="adRotator.set()" />
<input name="image" type="text" size="65"/>
一个非常棒的播放器,可惜如果图片是非常大的话,那结果有点惨!
js对子窗口的操作办法就很多,但是一要求对本窗口操作,我不太清楚!
下面再弄个,在页面上的动态时钟,秒秒都跳的哦,呵呵,不是falsh那种
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=gb2312"
/>
<
title
>
js核心对象之Date
</
title
>
<
script
type
="text/javascript"
>
function startTime()
{
var today=new Date()//定义一个时间对象
var h=today.getHours()//定义小时
var m=today.getMinutes()//定义分钟
var s=today.getSeconds()//定义秒
// add a zero in front of numbers<10
m=checkTime(m)//把分给checkTime处理
s=checkTime(s)//把秒给checkTime处理
document.getElementById('txt').innerHTML=h+":"+m+":"+s//在层txt中显示
t=setTimeout('startTime()',500)
}
function checkTime(i)
{//这函数意思很简单了,就是要实现01-09的效果
if (i<10) //
{i="0" + i}
return i
}
</
script
>
</
head
>
<
body
onload
="startTime()"
>
<
div
id
="txt"
></
div
>
</
body
>
</
html
>