JavaScript實現(xiàn)頁面跳轉(zhuǎn)的5種方法總結(jié)
更新時間:2023年12月19日 11:01:24 作者:天香自然,地上紅豆
在前臺開發(fā)中會涉及頁面跳轉(zhuǎn)的問題,下面這篇文章主要給大家總結(jié)介紹了關(guān)于JavaScript實現(xiàn)頁面跳轉(zhuǎn)的5種方法,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
我總結(jié)了這五種方法:
第一種:使用JS跳轉(zhuǎn)頁面
(1)跳轉(zhuǎn)帶參
<script language="javascript" type="text/javascript">
window.location.href="jingxuan.do?backurl=" rel="external nofollow" + window.location.href;
</script>(2)跳轉(zhuǎn)無參
<script>window.location.;</script>
第二種:返回上一次預(yù)覽界面
<script language="javascript">
alert("返回");
window.history.back(-1);
</script>HTML頁面嵌套
<a href="javascript:history.go(-1)" rel="external nofollow" >返回上一步</a>
<a href="<%=Request.ServerVariables(" rel="external nofollow" HTTP_REFERER")%>">返回上一步</a>第三種:button按鈕添加事件跳轉(zhuǎn)
<input name="前端知音" type="button" value="前端知音" onClick="location.href='login.do'">
第四種:在新窗口打開
<a href="javascript:" rel="external nofollow" onClick="window.open('login.do','','height=500,width=611,scrollbars=yes,status=yes')">新窗口</a>第五種:通過meta設(shè)置跳轉(zhuǎn)頁面
<head>
<!--只刷新不跳轉(zhuǎn) -->
<meta http-equiv="refresh" content="5">
<!--定時跳轉(zhuǎn) -->
<meta http-equiv="refresh" content="5;url=index.html">
</head>這里還有一個頁面?zhèn)髦?/p>
第一個頁面
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標(biāo)題文檔</title>
</head>
<SCRIPT LANGUAGE="JavaScript">
function test(){
var s = document.getElementById("txt");
location.href="test2.html?" rel="external nofollow" +"txt="+encodeURI(s.value);
}
</SCRIPT>
<body>
<input type="text" id="txt">
</br>
<input type="button" value="TEST" onclick="test()"/>
</body>
</html>第二個頁面
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標(biāo)題文檔</title>
</head>
<body>
<script language="javascript" type="text/javascript">
var loc = location.href;
var n1 = loc.length;//地址的總長度
var n2 = loc.indexOf("=");//取得=號的位置
var id = decodeURI(loc.substr(n2+1, n1-n2));//從=號后面的內(nèi)容
alert(id);
//document.write(id)
</script>
</body>
</html>總結(jié)
到此這篇關(guān)于JavaScript實現(xiàn)頁面跳轉(zhuǎn)的5種方法總結(jié)的文章就介紹到這了,更多相關(guān)JS頁面跳轉(zhuǎn)方法內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JavaScript?canvas實現(xiàn)字符雨效果
這篇文章主要為大家詳細(xì)介紹了JavaScript?canvas實現(xiàn)字符雨效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-06-06
一份老外寫的XMLHttpRequest代碼多瀏覽器支持兼容性
一份老外寫的XMLHttpRequest代碼多瀏覽器支持兼容性...2007-01-01
淺談通過JS攔截 pushState和replaceState事件
下面小編就為大家?guī)硪黄獪\談通過JS攔截 pushState和replaceState事件。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07

