First Take "http://www.cnblogs.com/wuxibolgs329/p/6188619.html#flag?test=12345" as an example, and then get the various components of it.
1, get the complete URL of the page
var a=location.href;
Console.log (a); "Http://www.cnblogs.com/wuxibolgs329/p/5261577.html#flag?test=12345"
2, get the domain name of the page
var host = Window.location.host; Www.cnblogs.com
var host2 = document.domain;//www.cnblogs.com
var a = Location.hostname; Www.cnblogs.com
3. Get URL Protocol
var A=location.protocol;
Console.log (a); http
4. Get the port
var A=location.port;
Console.log (a);
5, get the page path
var a=location.pathname;
Console.log (a);
6, set or get the URL of the Protocol section
var a = location.protocol;
7, get the part after the #
var A=window.location.hash;
var b=a.substr (1);
Console.log (b); flag?test=12345
8, get the href attribute followed by the question mark?
The case address changes to "http://www.cnblogs.com/wuxibolgs329/p/5261577.html?test=12345" at this time. Get test=12345
var a=location.search;
var b=a.substr (1);
Console.log (b);
//If the case is still "http://www.cnblogs.com/wuxibolgs329/p/5261577.html#flag?test=12345", the following wording is required to get test=12345
var a=location.href;
var b=a.substr ('? ') a.lastindexof +1);
Console.log (b);
9. Get the part after = number
var a=location.href;
var b=a.substring (a.lastindexof (' = ') +1);
Console.log (b); 12345
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, but also hope that a lot of support cloud Habitat community!