Generally speaking, page jumps can be performed through a tags, but in some cases, the page only has buttons or other tags. In this case, we need to use other methods to achieve page jumps. This article mainly shares with you commonly used js page jump codes, hoping to help everyone.
Solution:
Method 1: Location object
Test source code:
<html> <head> <script type="text/javascript"> //assign() 方法可加载一个新的文档。 function newDoc(){ window.location.assign("http://www.souvc.com/"); } //reload() 方法用于重新加载当前文档。这与用户单击浏览器的刷新按钮的效果是完全一样的。 function reloadPage(){ window.location.reload(); } //replace() 方法不会在 History 对象中生成一个新的记录。当使用该方法时,新的 URL 将覆盖 History 对象中的当前记录。 function replaceDoc(){ window.location.replace("http://www.souvc.com"); } function locationHref(){ window.location.href("http://www.w3school.com.cn/"); } </script> </head> <body> <input type="button" value="跳转页面(直接在按钮上加方法)" onClick="location.href='http://www.souvc.com/'"> <br/> <input type="button" value="跳转页面(加载一个新的文档)" onclick="newDoc()" /> <br/> <input type="button" value="重新加载页面" onclick="reloadPage()" /> <br/> <input type="button" value="Replace document" onclick="replaceDoc()" /> <input type="button" value="location href" onclick="locationHref()" /> </body> </html>
Method 2: History object
Method 3: Other objects
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
##href="javascript:history.go(-1)">Return to the previous step self.location='http://www.souvc.com/'; top.location='http://www.souvc.com/'; window.navigate("top.jsp"); |
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
##href="javascript:history.go(-1)">Return to the previous step self.location='http://www.souvc.com/'; top.location='http://www.souvc.com/'; window.navigate("top.jsp"); |
The above is the detailed content of Commonly used js page jump codes. For more information, please follow other related articles on the PHP Chinese website!