Javscript: How to pass and obtain parameters in the address bar of an HTML page. we know in the Javascript tutorial that the asp program on the server can accept parameters from the form on the html page, can I pass parameters to an html page, that is, add a question mark after html? The answer is yes.
The following is an implementation method of javascript. This function obtains parameters through the delimiter in window. location. href.
With this function, you can pass parameters between pages.
The following is a reference clip: /* * Function: obtain parameters from href. * SHref: http://www.yesky.com/arg.htm? Arg1 = d & arg2 = re * SArgName: arg1, arg2 * Return: the value of arg. d, re */ Function GetArgsFromHref (sHref, sArgName) { Var args = sHref. split ("? "); Var retval = ""; If (args [0] = sHref)/* the parameter is blank */ { Return retval;/* No processing required */ } Var str = args [1]; Args = str. split ("&"); For (var I = 0; I <args. length; I ++) { Str = args [I]; Var arg = str. split ("= "); If (arg. length <= 1) continue; If (arg [0] = sArgName) retval = arg [1]; } Return retval; } |