Home > Web Front-end > JS Tutorial > How to jump to the page using html/JavaScript

How to jump to the page using html/JavaScript

青灯夜游
Release: 2023-01-05 16:07:43
Original
3350 people have browsed it

How to jump to the page: 1. In HTML, you can use the meta tag to jump, with the syntax ""; 2. In JavaScript, you can use the href attribute of the location object to jump, with the syntax "window. location.href=Page address".

How to jump to the page using html/JavaScript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

html/JavaScript to achieve page jump

1. Use meta to jump in html. You can set the jump time and page through meta

<head>
    <!--只是刷新不跳转到其他页面 -->
    <meta http-equiv="refresh" content="5">
    <!--定时转到其他页面 -->
    <meta http-equiv="refresh" content="5;url=index.html"> 
</head>
Copy after login

2. Jump to the previous page through javascript

1 // 直接跳转
2 window.location.href='index.html';
3 // 定时跳转
4 setTimeout("javascript:location.href='index.html'", 5000);
Copy after login

html

window.history.go(-1); or window.history .back(-1);

<script type="text/javascript">
    var wrong = document.getElementById('btn');
    wrong.onclick = function() { 
    window.history.go(-1);//返回上一页
     window.history.back(-1);//返回上一页
   }
</script>
Copy after login

Write in html

<a href=”#” onClick=”JavaScript :history.back(1);”>返回上一页</a>
<a href=”#” onClick=”javascript :history.Go(-1);”>返回上一页</a>
Copy after login

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of How to jump to the page using html/JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template