However, if these three pages are under the same domain name, you can use Javascript's document.cookie to record the URL of each visit.
The example I wrote needs four files, url_history.js, 1. , 2.,3. (The contents of the three files are the same), and the code is written in the space (hi.baidu/keneks/item/50692e21f9300d0c72863e4d).
Copy and paste, put url_history.js together with the other three files, visit any page, click any link, and the page you visited will be automatically displayed.
Historical urls are stored in the url_history variable in the form of an array, so url_history[0] is the previous one, url_history[ 1] is the previous one, and so on.
Second, how does js get the URL of the first two pages?
The code is as follows:
3. How to use js to obtain the modified URL and use js to operate the current URL? You can use the built-in object window.locationWindow.location has the following properties: window.location.href: Get the complete URL in the current address bar, and you can change the URL in the current address bar by assigning a value; Window.location.search gets the parameter part of the current URL, that is, "?" The latter part (including question mark) can change the parameter part of URL by assigning values; Window.location.hash: Obtain the anchor point contained in the current URL, that is, the part after "#" (including #), and you can change the anchor point part of the URL by assigning values; Window.location.host: Get the host information in the current URL, including the port number, which can be changed by assignment; Window.location.hostname: Get the domain name part in the current URL, excluding the port number, and you can change the domain name by assigning values; Window.location.port: get the port number in the current URL, which can be changed by assignment; Window.location.pathname: Get the path information in the current URL, that is, the part between the domain name and parameters, and you can change the path of the current URL by assigning values; Window.location.protocol: Get the protocol part of the current URL, such as:,:, etc. You can change the protocol part of the URL by assigning values; Window.location has the following methods: window.location.replace(url): replace the current url with the incoming URL string, which will replace the URL in the history, that is, this method will overwrite the previous history; Window.location.reload (): Reload the current URL, which is equivalent to refreshing; Window.location.assign(url): Load the incoming url, and this method will not overwrite the previous history; .
Four. How to get several URL addresses with JS The following is how to get MAC address, IP address and host name with JS: The copy code is as follows:
Verb (abbreviation of verb) how to get the url of the previous page in js is as follows:
1. Sets or gets the entire URL as a string: window.location.href.
2. Set or get the port number associated with URL: window.location.port
3. Set or get the protocol part of the URL window. location.protocol
4. Set or get the window.location.search part after the question mark in the href attribute.
5. Get the value of the variable (remove the part after the equal sign)
6. Set or get the protocol part of URL: window.location.protocol
7. Set or get the segment after the pound sign in the href attribute: window.location.hash
8. Set or get the host name and port number of the location or URL: window.location.host
Sixth, how to use js to obtain and modify URL. Using js to operate the current URL, you can use the built-in object window.location.
Window.location has the following properties:
Window.location.href: Get the complete URL in the current address bar, and you can change the URL in the current address bar by assigning a value;
Window.location.search gets the parameter part of the current URL, that is, "?" The latter part (including question mark) can change the parameter part of URL by assigning values;
Window.location.hash: Obtain the anchor point contained in the current URL, that is, the part after "#" (including #), and you can change the anchor point part of the URL by assigning values;
Window.location.host: Get the host information in the current URL, including the port number, which can be changed by assignment;
Window.location.hostname: Get the domain name part in the current URL, excluding the port number, and you can change the domain name by assigning values;
Window.location.port: get the port number in the current URL, which can be changed by assignment;
Window.location.pathname: Get the path information in the current URL, that is, the part between the domain name and parameters, and you can change the path of the current URL by assigning values;
Window.location.protocol: Get the protocol part of the current URL, such as:,:, etc. You can change the protocol part of the URL by assigning values;
Window.location has the following methods:
Window.location.replace(url): replaces the current url with the entered URL string. This method will replace the URL in the history, that is, this method will overwrite the previous history;
Window.location.reload (): Reload the current URL, which is equivalent to refreshing;
Window.location.assign(url): Load the incoming url, and this method will not overwrite the previous history;