First, we will introduce the method for processing URLs in JS: URL example: http: // localhost/test/test.htm? Id = 1
<SCRIPT merge Ge = JavaScript>
Alert (window. Location. pathname); -- returns/test/test.htm
Alert (window. Location. Search); -- return? Id = 1
Alert (window. Location. href); -- Return http: // localhost/test/test.htm? Id = 1
</SCRIPT>--------------------------------- The location object contains information about the current URL. The entire URL string of the href attribute.
The Protocol contains the first part of the URL, such as http:
Host contains a string containing the host name in the URL: port number, for example, // www.zzcn.net/server/
Hostname a string containing the host name in the URL. For example, http://www.zzcn.net /;
Port contains the possible port number strings in the URL.
The part after "/" in the pathname URL. For example ~ LIST/index.htm
String after hash "#" (CGI parameter.
Search "? "# (CGI parameter.
Functions used to receive Parameters Using Js in HTML
Function getparameter (PARAM)
{
VaR query = Window. Location. search;
VaR ilen = Param. length;
VaR istart = query. indexof (PARAM );
If (istart =-1)
Return "";
Istart + = ilen + 1;
VaR iend = query. indexof ("&", istart );
If (iend =-1)
Return query. substring (istart );
Return query. substring (istart, iend );
}
When used: var temp = getparameter ("passed parameters ");
Xx.htm? Xx = xx. Haha ,,,