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
By default, MySQL character types are not case-se...
1. Introduction to nmon Nmon (Nigel's Monitor...
Recently, we have been capturing SQL online for o...
Table of contents 0. Background 1. Installation 2...
Regarding the issue of MySQL remote connection, w...
Overflow Hide It means hiding text or image infor...
Preface This article is just a simple record of m...
Newbie, record it yourself 1. Install supervisor....
Use pure CSS to change the background color of a ...
Because some dependencies of opencv could not be ...
1. Unzip to the location where you want to instal...
1. The difference between forward proxy and rever...
1. Log in to MySQL database mysql -u root -p View...
This article example shares the specific code for...
Inserting images into HTML requires HTML tags to ...