The following example shows a URL and obtains its components.
Http://www.nowamagic.net/newsDetail.php? Id = 65
Window. Location. href
You can obtain the entire URL string (the complete address bar in the browser ).
1 var test = Window. Location. href; 2 alert (test );
ProgramReturn
Http://www.nowamagic.net/newsDetail.php? Id = 65
Window. Location. Protocol
Obtain the URL protocol section.
1 var test = Window. Location. Protocol; 2 alert (test );
The program returns http:
Window. Location. Host
Obtain the host part of the URL.
1 var test = Window. Location. Host; 2 alert (test );
The program returns www.nowamagic.net
Window. Location. Port
Obtain the URL Port
VaR test = Window. Location. Port; alert (test );
If the default port 80 is used (Update: Even if port 80 is added), the return value is not the default port 80, but a null character.
Window. Location. pathnameObtain the URL path (that is, the file address)
VaR test = Window. Location. pathname; alert (test );
Window. Location. Search
In addition to assigning values to dynamic languages, we can also give static pages and use JavaScript to obtain expected parameter values.
VaR test = Window. Location. Search; alert (test );
|
|
Window. Location. Hash
Obtain the anchor.
1 var test = Window. Location. Hash; 2 alert (test );
Reprinted from: http://www.nowamagic.net/javascript/js_GetUrl.php