Preface: The window object provides us with a 1. Location Object1. URL The general syntax of a URL is:
2. Properties of the location objectWe can use these properties to get the corresponding information in the address bar, for example:
Or we can directly enter the corresponding attributes in the console to get the corresponding return value. For example, we now make an effect of clicking a button to jump to the page: <body> <button>Jump</button> <div></div> <script> var btn = document.querySelector('button'); var div = document.querySelector('div'); var timer = 5; btn.addEventListener('click',function(){ time() }) var time = setInterval(function(){ if(timer == 0) { this.location.href = 'https://www.baidu.com' } else{ div.innerHTML = 'The page will jump after '+timer+' seconds' timer--; } },1000); </script> </body> The running results are: 3. Location object methodsFor example, we can also jump to the page by using the location object method: <button>Click to jump</button> <script> var btn = document.querySelector('button'); btn.addEventListener('click',function(){ location.assign('https://www.baidu.com') }) </script> The jump achieved by 2. Navigator Object if((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) { window.location.href = ""; //mobile phone} else { window.location.href = ""; //computer} 3. History Object The three most commonly used methods are:
For example, if we have two pages and want to use one button to go forward and backward, we can bind the forward method and history method to the buttons of the two pages respectively, as shown below: <body> <a href="list.html" rel="external nofollow" >Go to the list page</a> <button>Forward</button> <script> var btn = document.querySelector('button'); btn.addEventListener('click',function(){ history.forward() }) </script> </body> <body> <a href="index.html" rel="external nofollow" >Return to the main page</a> <button>Back</button> <script> var btn = document.querySelector('button'); btn.addEventListener('click',function(){ history.back() }) </script> </body> The effect is: Or we can use This is the end of this article about You may also be interested in:
|
<<: CSS3 speeds up and delays transitions
>>: Implementation of Nginx Intranet Standalone Reverse Proxy
1. Create a new virtual machine in VMware 15.5 1....
In order to efficiently meet requirements and avo...
Table of contents Short Polling Long-Polling WebS...
Preface: This article mainly introduces the query...
XML/HTML CodeCopy content to clipboard < div c...
After setting up the MySQL master-slave, you ofte...
Table of contents 1. How the Bootstrap grid syste...
Table of contents 1. One-way value transfer betwe...
Function: Jump to the previous page or the next p...
1. Installation Search the mariadb version to be ...
1. What is a transaction? A database transaction ...
1. float+overflow:hidden This method mainly trigg...
Here is the mysql driver mysql.data.dll Notice: T...
Copy code The code is as follows: @charset "...
Background In Docker, four containers are created...