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
Copy codeThe 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

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.