var url;
 
url = window.location.href; /* Get the full URL */
alert(url); / * * / http://127.0.0.1:8020/Test/index.html#testname=test

url = window.location.pathname; /* Get the file path (file address) */
alert(url); /* /Test/index.html */

url = window.location.protocol; /* Get the protocol */
alert(url); /* http */

url = window.location.host; /* Get the host address and port number */
alert(url); / * * / http://127.0.0.1:8020/

url = window.location.hostname; /* Get the host address */
alert(url); / * * / http://127.0.0.1/

url = window.location.port; /* Get the port number */
alert(url); / * * / 8020

url = window.location.hash; /* Get the anchor point (segment after "#") */
alert(url); /* #test? name=test */

url = window.location.search; /* Get attributes ("? ") Section after) */
alert(url);

/* If you need a part of the URL, you can do it yourself */
url = window.location.pathname;
url = url.substring(url.lastIndexOf('/') + 1, url.length);
alert(url); /* /index.html */

/* * If the page is frameset * to get the URL of the specified page * just change the window to the specified page */
/* 'frame' specifies the page class name */
var url = window.parent.frames['frame'].location.href;
/* Gets the URL */ displayed in the current address bar
var url = window.parent.location.href;
/* window parent interchangeable */
var url = parent.window.location.href;
Copy the code