Use JavaScript to obtain the regular expression of a URL parameter (used to obtain a parameter value)

Source: Internet
Author: User

Example:
// JavaScript parameters (multiple parameters)
VaR url = "B. aspx? Txta = "+ document. getelementbyid (" txtname "). value;
URL + = "& txtb =" + document. getelementbyid ("txtage"). value;
Window. open (URL, 'xwindow', 'width = 640, Height = 400, status = No, toolbar = No, menubar = No, location = No, scrollbars = Yes, resizable = No, top = 250, Left = 430 ');
// Obtain the target page of B. aspx CopyCode The Code is as follows: <scirpt Language = 'audio cirpt'>
<! --
Function getstringvalue ()
{
String. Prototype. getquerystring = function (name) // name is the URL parameter name.
{
VaR Reg = new Regexp ("(^ | & | \\?) "+ Name +" = ([^ &] *) (& | $) "), R;
If (r = This. Match (REG) return Unescape (R [2]); return NULL;
};
// You can directly pass the parameter name to obtain the parameter value.
Alert (window. Location. href. getquerystring ("txta") + window. Location. href. getquerystring ("txtb "));
}
-->
</Scirpt>

Differences between window. Open and window. Location:
Window. Open is to open a new window
Window. Location is to replace this page, that is, to locate
Onclick = "javascript: window. Location. href = 'xxxx. aspx ';"
The javascript URL parameter is read from the simplified version.
Http://www.jb51.net/article/17116.htm

Related Article

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.