It is not difficult to obtain URL parameter information through JavaScript, and there are many methods. The reason for using this method is that it uses regular expressions and is very concise.
-
- FunctionGetquery (name)
-
- {
-
- VaRReg =NewRegexp ("(^ | &)"+ Name +"= ([^ &] *) (& | $ )");
-
- VaRR = Window. Location. Search. substr (1). Match (REG );
- If(R! =Null)
-
- ReturnUnescape (R [2]);
-
- Return Null;
-
- }
For example, you need to use JavaScript to display different error messages on the page based on different values of the URL parameter errtype:
- <Div ID="Diverror" Style="Color: red; font-weight: bold; text-align: center; width: 100%; Height: 300px; padding-top: 30px ;"></Div>
-
-
- <Script Language="JavaScript">
-
-
- // Define the descriptions of errors
- VaRErrinfos= {"1": "The submitting user shoshould not be allowed to review his submissions ",
-
- "2": "reviewers cannot review the same submission twice ",
-
- "3": "Only people in the" reviewers "group shocould be able to access the Review Form"
- }
-
-
- Function getquery (name)
-
- {
-
- VaRReg=NewRegexp ("(^ | &)" + name + "= ([^ &] *) (& | $ )");
- VaRR=Window. Location. Search. substr (1). Match (REG );
-
- If (R! = NULL)
-
- Return Unescape (R [2]);
-
- Return NULL;
-
- }
-
- VaRErrtype=Getquery("Errtype ")
-
- If (errtype)
-
- Document. getelementbyid ("diverror "). Innertext=Errinfos[Errtype]
-
- </Script>