概述javascript
相信不少Web開發者都知道,在開發Web程序的時候,對於頁面之間的跳轉,有不少種,可是有效的跳轉則事半功倍,下面就是我在平時的開發過程當中所用到的一些JavaScript跳轉方式,拿出和你們共享一下。html
第一種:直接跳轉加參數java
<script language="javascript" type="text/javascript">
window.location.href="login.jsp?backurl="+window.location.href;
</script>
直接跳轉無參數:框架
<script>window.location.href='http://www.baidu.com';</script>
第二種:返回上一次預覽界面jsp
<script language="javascript">
alert("返回");
window.history.back(-1);
</script>
標籤嵌套:post
<a href="javascript:history.go(-1)">返回上一步</a>
<a href="<%=Request.ServerVariables("HTTP_REFERER")%>">返回上一步</a>
第三種:指定跳轉頁面 對框架無效。。。url
<script language="javascript">
window.navigate("top.jsp");
</script>
第四種:指定自身跳轉頁面 對框架無效。。spa
<script language="JavaScript">
self.location='top.htm';
</script>
第五種:指定自身跳轉頁面 對框架有效。。code
<script language="javascript">
alert("非法訪問!");
top.location='xx.aspx';
</script>
第六種:按鈕式 在button按鈕添加 事件跳轉。。
htm
<input name="pclog" type="button" value="GO" onClick="location.href='login.aspx'">
第七種:在新窗口打開:
<a href="javascript:" onClick="window.open('login.aspx','','height=500,width=611,scrollbars=yes,status=yes')">開新窗口</a>
應用實例:
<head>
<script language="javascript">
function old_page()
{
window.location = "login.aspx"
}
function replace()
{
window.location.replace("login.aspx")
}
function new_page()
{
window.open("login.aspx")
}
</script>
</head>
<body>
<input type="button" onclick="new_page()" value="在新窗口打開s"/>
<input type="button" onclick="old_page()" value="跳轉後有後退功能"/>
<input type="button" onclick="replace()" value="跳轉後沒有後退功能"/>
</body>
-轉載