JavaScript實現(xiàn)頁面跳轉(zhuǎn)的5種方法總結
更新時間:2023年12月19日 11:01:24 作者:天香自然,地上紅豆
在前臺開發(fā)中會涉及頁面跳轉(zhuǎn)的問題,下面這篇文章主要給大家總結介紹了關于JavaScript實現(xiàn)頁面跳轉(zhuǎn)的5種方法,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
我總結了這五種方法:
第一種:使用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>
第二種:返回上一次預覽界面
<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設置跳轉(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>無標題文檔</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>無標題文檔</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>
總結
到此這篇關于JavaScript實現(xiàn)頁面跳轉(zhuǎn)的5種方法總結的文章就介紹到這了,更多相關JS頁面跳轉(zhuǎn)方法內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
JavaScript模擬實現(xiàn)網(wǎng)易云輪播效果
這篇文章主要介紹了如何利用JavaScript模仿網(wǎng)易云輪播效果的實現(xiàn),文中的示例代碼講解詳細,對我們學習有一定幫助,需要的可以參考一下2022-04-04JavaScript實現(xiàn)樹結構轉(zhuǎn)換的五種方法總結
在?JavaScript?編程中,將數(shù)組轉(zhuǎn)換為樹結構是一個常見的需求。本篇博客將介紹五種常用的方法來實現(xiàn)數(shù)組轉(zhuǎn)樹結構,希望對大家有所幫助2023-03-03文字溢出實現(xiàn)溢出的部分再放入一個新生成的div中具體代碼
說文字溢出,如何實現(xiàn)溢出的文字放入一個新生成的div中,原理就是判斷是否能在div里放下,如果不能,則在應該斷開的地方,差入到新的div中2013-05-05JavaScrip報錯:module?is?not?defined的原因及解決
這篇文章主要給大家介紹了關于JavaScrip報錯:module?is?not?defined的原因及解決方法,文中通過代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-09-09JavaScript中定時器setTimeout()和setInterval()的用法
本文詳細講解了JavaScript中定時器setTimeout()和setInterval()的用法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-06-06