JavaScript and Ajax for the Web, Sixth Edition
Redirecting the User with a Link
You can check for the existence of JavaScript and then seamlessly redirect , or send users to another page, depending on if they have JavaScript turned on. This example shows you how to embed the redirection in a link. We'll use two HTML pages and one JavaScript file. The first HTML page, Script 2.9 , gives the user the link to click. Script 2.10 is the JavaScript file, and Script 2.11 is the HTML page the user is redirected to if they have JavaScript enabled. Figure 2.6 shows the starting point for users. When they click the link, they'll be taken to one of two pages, depending on whether or not they have JavaScript. Script 2.9. This HTML allows you to redirect the user based on a link.
Script 2.10. By embedding the redirection inside the code, the user doesn't even know your script intervened in the link.
Script 2.11. This is the HTML for the page the JavaScript-enabled user ends up on.
Figure 2.6. This page has the link that contains the redirection code.
To redirect a user:
Tip
|
Категории