You can seamlessly redirect users to another page based on whether they have enabled the JavaScript function. This example shows how to embed the redirection function into the link. Two HTML pages and a JavaScript file will be used below.
The first HTML page shows the connection to the user:
Test.html
[Html]
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> Welcome to our site </title>
<Script type = "text/javascript" src = "script01.js">
</Script>
</Head>
<Body bgcolor = "# FFFFFF">
<H2 align = "center">
<A href = "script01.html" id = "redirect"> Welcome to our site... c 'mon in! </A>
</H2>
</Body>
</Html>
The second HTML page is the HTML page that the user is redirected to when the JavaScript function is enabled.
Jswelcome.html
[Html]
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> Our site </title>
</Head>
<Body bgcolor = "# FFFFFF">
<H1> Welcome to our web site, which features lots of cutting-edge JavaScript </Body>
</Html>
Script01.js
[Javascript]
Window. onload = initAll;
Function initAll (){
Document. getElementById ("redirect"). onclick = initRedirect;
}
Function initRedirect (){
Window. location = "jswelcome.html ";
Return false;
}
Script01.html
[Html]
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> My JavaScript page </title>
</Head>
<Body bgcolor = "# FFFFFF">
<Noscript>
<H2> This page requires JavaScript. </Noscript>
</Body>
</Html>
When the user opens "test.html", their users enable the javascriptfunction and will be taken to one of the script01.htmlor jswelcome.html pages.
In the js file
[Javascript]
Function initRedirect (){
Window. location = "jswelcome.html ";
Return false;
}
If you call this function, it sets window. location (the page displayed in the browser) to a new page. Return false indicates that the processing of user clicks is stopped, so that the page specified in the href page is not loaded. the coolest feature of this method is that, after the redirection is completed, the user will not realize that the page has been redirected. (Source JavaScript basic tutorial)
From Yanghai