打开网页让它自动打开另一个链接网页
一、最基本的弹出窗口代码
<SCRIPT LANGUAGE="javascript">
<!--
window.open ('www.eqing/index.html')
-->
</SCRIPT>
二、经过设置后的弹出窗口
<SCRIPT LANGUAGE="javascript">
<!--
window.open ('www.eqing/index.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> 中国移动上海网点
这里定义了一个函数openwin(),函数内容就是打开一个窗口。在调用它之前没有任何用途。
怎么调用呢?
方法一:<body onload="openwin()"> 浏览器读页面时弹出窗口;
方法二:<body onunload="openwin()"> 浏览器离开页面时弹出窗口;
方法三:<a href="#" onclick="openwin()">打开一个窗口</a> 注意:使用的“#”是虚连接。
方法四:<input type="button" onclick="openwin()" value="打开窗口">
四、同时弹出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)不要相同
五、主窗口打开文件,同时弹出小窗口
如下代码加入主窗口<head>区:
<script language="javascript">
<!--
function openwin() {
window.open("page.html","","width=200,height=200")
}
//-->
</script>
<body>区加入:
<a href="1.htm" onclick="openwin()">open</a>
即可。
六、弹出的窗口之定时关闭控制
如下代码加入page.html文件的<head>区:
<script language="JavaScript">
function closeit() {
setTimeout("self.close()",10000) //毫秒
}
</script>
然后,再用<body onload="closeit()">
七、内包含的弹出窗口-一个页面两个窗口
通过下面的例子,你可以在一个页面内完成上面的效果。
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function openwin()
{
OpenWindow=window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no");
//写成一行
OpenWindow.doc
ument.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>
看看 OpenWindow.document.write()里面的代码不就是标准的HTML吗?只要按照格式写更多的行即可。千万注意多一个标签或少一个标签就会出现错误。记得用OpenWindow.document.close()结束啊。
八、终极应用--弹出的窗口之Cookie控制
将如下代码加入主页面HTML的<HEAD>区:
<script>
function openwin(){
window.open("page.html","","width=200,height=200")
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (kie.length > 0) {
offset = kie.indexOf(search)
if (offset != -1) {
offset += search.length
end = kie.indexOf(";", offset); 耐玩又不氪金的手游2020
if (end == -1)
end = kie.length;
returnvalue=kie.substring(offset, end))
}
}
return returnvalue;
}
function loadpopup(){
if (get_cookie('popped')==''){
openwin()
}
}
</script>
然后,用<body onload="loadpopup()"> 

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。