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