Home > Web Front-end > JS Tutorial > JavaScript link redirects user

JavaScript link redirects user

高洛峰
Release: 2016-11-26 09:39:01
Original
1258 people have browsed it

The user can be redirected seamlessly, that is, the user can be redirected to another page based on whether the user has turned on the JavaScript function. This example demonstrates how to embed redirect functionality into a link, using two HTML pages and a JavaScript file.
The first HTML page displays the connection to the user:
test.html
[html]


< title>Welcome to our site







The second HTML page is the HTML page that the user is redirected to when the JavaScript function is enabled.
jswelcome.html
[html]


Our site
< /head>
script01.js
[javascript]
window.onload = initAll;

function initAll() {
document.getElementById("redirect").onclick = initRedirect;
}

function initRedirect() {
window.location = "jswelcome.html";
return false;
}

script01.html
[html]


My JavaScript page





When a user opens "test.html", they will be taken to two pages, script01.html or jswelcome.html, depending on whether they have javascript turned on one.
[javascript]
function initRedirect() {
in the js file page) is set as a new page. Return false means to stop processing the user's click, so that the page specified in the href page will not be loaded. The coolest feature of this method is that the redirection is completed and the user will not realize that the page has been redirected at all.

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