在一个网页中自动打开另一个网页(ZZ)

//也可以用Response.redirect()方法来重定向 added by zhangjun at 2011-1-20
一、最基本的弹出窗口代码 

<SCRIPT LANGUAGE="javascript"> 
<!-- 
window.open ('http://www.eqing.com.cn/index.html') 
--> 
</SCRIPT> 
二、经过设置后的弹出窗口

<SCRIPT LANGUAGE="javascript"> 
<!-- 
window.open ('http://www.eqing.com.cn/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.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> 
看看 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 (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> 
 然后,用<body onload="loadpopup()">
原文地址:https://www.cnblogs.com/zhangjun1130/p/1940274.html