经常上网的朋友可能会到过这样一些网站,一进入首页立刻会弹出一个窗口,或者按一个连接或按钮弹出,通常在这个窗口里会显示一些注意事项、版权信息、警告、欢迎光顾之类的话或者作者想要特别提示的信息。其实制作这样的页面效果非常的容易,只要往该页面的html里加入几段javascript代码即可实现。下面俺就带您剖析它的奥秘。
【1、最基本的弹出窗口代码】
其实代码非常简单:
| 以下是引用片段: <script language="javascript"> <!-- window.open ('page.html') --> </script> |
| <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> |
| <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 onload="openwin()"> ...任意的页面内容... </body> </html> |
| <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> |
| <script language="javascript"> <!-- function openwin() {window.open("page.html","","width=200,height=200") } //--> </script> |
| <script language="javascript"> function closeit() {settimeout("self.close()",10000) //毫秒} </script> |
| <html> <head> <script language="javascript"> 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="#" onclick="openwin()">打开一个窗口</a> <input type="button" onclick="openwin()" value="打开窗口"> </body> </html> |
| <script> function openwin() {window.open("page.html","","width=200,height=200")} function get_cookie(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; } function loadpopup(){ if (get_cookie('popped')==''){ openwin() document.cookie="popped=yes" } } </script> |
|