Application of location object attributes and methods (URL resolution)

Source: Internet
Author: User

The location object provides many attributes and methods for parsing URLs. Copy codeThe Code is as follows: <Title> </title>
<Script type = "text/javascript">
Var uristr = window. location. search. substr (1 );
Var array = uristr. split ('&&');
For (var I = 0; I <array. length; I ++ ){
Var array1 = array [I]. split ('= ');
Alert (array1 [0]);
}
------------------ // Hash: returns the content after # symbol.
Function showhash (){
Alert (window. location. hash );
}
------------------ // Host: Server Name
Function showhost (){
Alert (window. location. host );
}
-------------------- // Href: the complete URL of the currently loaded page
Function showhref (){
Alert (window. location. href );
}
------------------ // Pathname: the part after the host name in the url
Function showpathname (){
Alert (window. location. pathname );
}
------------------ // Protocal: the protocol used in the URL
Function showprotacal (){
Alert (window. location. protocal );
}
-------------------- // Search: the part after the question mark in the URL where the get request is executed, also known as the query string.
Function showsearch (){
Alert (window. location. search );
}
</Script>
</Head>
<Body>
<Input type = "button" value = "Hash" onclick = "showhash ();"/>
<Br/>
<Input type = "button" value = "host" onclick = "showhost ();"/>
<Br/>
<Input type = "button" value = "href" onclick = "showhref ();"/>
<Br/>
<Input type = "button" value = "pathname" onclick = "showpathname ();"/>
<Br/>
<Input type = "button" value = "protocal" onclick = "showprotacal ();"/>
<Br/>
<Input type = "button" value = "search" onclick = "showsearch ();"/>
</Body>
During the search test, you need to click a connection from another page and pass through the browser address bar:
<Body>
<A href = "HTMLPage1.htm? Name = 'wang 5' & age = 22 "> GO </a>
</Body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.