Home > Web Front-end > JS Tutorial > body text

js gets the URL information of the current page_javascript skills

WBOY
Release: 2016-05-16 16:44:49
Original
1187 people have browsed it

1. Set or get the entire URL as a string:

window.location.href

2. Set or get the port number associated with the URL:

window.location. port

3. Set or get the protocol part of the URL

window.location.protocol

4. Set or get the part following the question mark in the href attribute

window.location.search

5. Get the value of the variable (intercept the part after the equal sign)

Copy code The code is as follows:

var url = window.location.search;
// alert(url.length);
// alert(url.lastIndexOf('= '));
var loc = url.substring(url.lastIndexOf('=') 1, url.length);

6. Set or get the protocol part of the URL:

window.location.protocol

7. Set or get the segment after the hash sign "#" in the href attribute:

window.location.hash

8. Set or get the hostname and port number of location or URL:

window.location.host
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template