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
For Centos installation of MySQL, please refer to...
Element UI implements multiple tables scrolling a...
Table of contents 1. Introduction 2. Back up the ...
Table of contents 1. Install Docker 2. Install an...
Table of contents el-scrollbar scroll bar el-uplo...
I recently encountered a problem at work. The doc...
Features of MySQL: MySQL is a relational database...
This article records the detailed installation tu...
This article uses an example to describe how to v...
There was an article about the execution process ...
The Golden Rule No matter how many people are wor...
Data Types and Operations Data Table 1.1 MySQL ty...
I want to make a docker for cron scheduled tasks ...
This article introduces the development environme...
Table of contents 1: Build webpack 2. Data hijack...