javascript打开新窗口同时关闭旧窗口
人气:1
其实这个问题和浏览器的版本息息相关,作为菜鸟的我,直到现在也没有找到完美的解决办法。没办法,因为业务必须要实现,所以只好用另一种方法去做了:
通过重定向URL实现打开新窗口的同时“关闭”旧窗口
test1.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> test1 </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script type="text/javascript">
function toNewWindow() {
window.top.location.href="test2.html";
}
</script>
<BODY>
<input type="button" value="打开另一个页面test2.html" onclick="toNewWindow()">
</BODY>
</HTML>
test2.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>test2.html</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
通过重写URL,打开了要跳转的页面test2.html
</BODY>
</HTML>
附:页面跳转的各种方法
第一种:
<script language="javascript" type="text/javascript">
window.location.href="/login.jsp?backurl="+window.location.href;
</script>
第二种:
<script language="javascript">
alert("返回");
window.history.back(-1);
</script>
第三种:
<script language="javascript">
window.navigate("top.jsp");
</script>
第四种:
<script language="JavaScript">
self.location='top.htm';
</script>
第五种:
<script language="javascript">
alert("非法访问!");
top.location='xx.jsp';
</script>
=====javascript中弹出选择框跳转到其他页面=====
<script language="javascript">
<!--
function logout()...{
if (confirm("你确定要注销身份吗?是-选择确定,否-选择取消"))...{
window.location.href="/logout.asp?act=logout"
}
}
-->
</script>
=====javascript中弹出提示框跳转到其他页面=====
<script language="javascript">
<!--
function logout()...{
alert("你确定要注销身份吗?");
window.location.href="/logout.asp?act=logout"
}
-->
</script>
通过重定向URL实现打开新窗口的同时“关闭”旧窗口
test1.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> test1 </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script type="text/javascript">
function toNewWindow() {
window.top.location.href="test2.html";
}
</script>
<BODY>
<input type="button" value="打开另一个页面test2.html" onclick="toNewWindow()">
</BODY>
</HTML>
test2.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>test2.html</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
通过重写URL,打开了要跳转的页面test2.html
</BODY>
</HTML>
附:页面跳转的各种方法
第一种:
<script language="javascript" type="text/javascript">
window.location.href="/login.jsp?backurl="+window.location.href;
</script>
第二种:
<script language="javascript">
alert("返回");
window.history.back(-1);
</script>
第三种:
<script language="javascript">
window.navigate("top.jsp");
</script>
第四种:
<script language="JavaScript">
self.location='top.htm';
</script>
第五种:
<script language="javascript">
alert("非法访问!");
top.location='xx.jsp';
</script>
=====javascript中弹出选择框跳转到其他页面=====
<script language="javascript">
<!--
function logout()...{
if (confirm("你确定要注销身份吗?是-选择确定,否-选择取消"))...{
window.location.href="/logout.asp?act=logout"
}
}
-->
</script>
=====javascript中弹出提示框跳转到其他页面=====
<script language="javascript">
<!--
function logout()...{
alert("你确定要注销身份吗?");
window.location.href="/logout.asp?act=logout"
}
-->
</script>
加载全部内容