Home > Article > Web Front-end > An in-depth analysis of the window.location object to implement page jumps
This article brings you relevant knowledge about javascript, which mainly introduces the issues related to the window.location object to achieve page jump. The window.location object is used to obtain the address of the current page. , and redirect the browser to a new page. Let’s take a look at it. I hope it will be helpful to everyone.
[Related recommendations: javascript video tutorial, web front-end】
window.location object is used Get the address (URL) of the current page and redirect the browser to the new page.
window location The object can be written without using the Window prefix. Some examples:
##Example
Return the URL of the current page:<script type="text/javascript"> document.write(location.href); </script>The output of the above code is:
http://127.0.0.1:8848/7.11/new_file.html
Example
Return the path name of the current URL:<script type="text/javascript"> document.write(location.pathname); </script>The output of the above code is:
/7.11/new_file.htmlwindow location AssignThe location.assign() method loads a new document.
Example
Load a new document:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <input type="button" name="" id="" value="跳转到百度" onclick="newDoc()"/> <script type="text/javascript"> function newDoc(){ window.location.assign('https://www.baidu.com') } </script> </body> </html>
Use javascript to implement page timing jump---location object
Requires the following effects:
## Code implementation ideas :
css code:
js code:
Achievement effect:
【Related recommendations:
javascript video tutorialThe above is the detailed content of An in-depth analysis of the window.location object to implement page jumps. For more information, please follow other related articles on the PHP Chinese website!