Js method for obtaining parameters from pages. js method for obtaining page Parameters

Source: Internet
Author: User

Js method for obtaining parameters from pages. js method for obtaining page Parameters

This article mainly introduces how to use window. location. search to obtain parameters from the page.

function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i"); var r = window.location.search.substr(1).match(reg); if (r!=null) return (r[2]); return null; } var sname = GetQueryString("name"); if(sname!=null) { var sname_ = decodeURIComponent(sname); alert(sname_); }

Test

Abcd.html? Name = xyz

Xyz should pop up


How does Javascript in html obtain parameters passed through the POST method?

Javascript in html cannot obtain the parameters passed through the post method on the server.
However, php jsp and asp can

How to obtain parameters in js

Upload the following values on page:

Window. showModalDialog ("ModalDialogFrame. aspx? Title = select Organization Department & PageUrl = ParentTreeView. aspx ", window," dialogWidth = paipx; dialogHeight = paipx; status = no; center = yes ;");

Upload the following values on page:

Window. showModalDialog ("ModalDialogFrame. aspx? Title = select Organization Department & PageUrl = ParentTreeView. aspx ", window," dialogWidth = paipx; dialogHeight = paipx; status = no; center = yes; "); view plaincopy to clipboardprint?

On the page ModalDialogFrame. aspx:

Function GetQueryString (sProp)

{

Var re = new RegExp ("[&,?] "+ SProp +" = ([^ \ &] *) "," I ");

Var a = re.exe c (document. location. search );

If (a = null)

Return "";

Return a [1];

}

On the page ModalDialogFrame. aspx:

Function GetQueryString (sProp)

{

Var re = new RegExp ("[&,?] "+ SProp +" = ([^ \ &] *) "," I ");

Var a = re.exe c (document. location. search );

If (a = null)

Return "";

Return a [1];

} View plaincopy to clipboardprint?

Call method:

Var url = GetQueryString ("PageUrl"); // ParentTreeView. aspx

Var title = GetQueryString ("Title"); // select an organizational unit

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.