This article illustrates four ways in which JavaScript implements parameter transfer between HTML pages. Share to everyone for your reference, specific as follows:
We know that programs on the server side asp,jsp can accept the parameters from the form on the HTML page. So, can you pass the parameters to the HTML page? OK.
Principle: To obtain the parameters by the window.location.href of the separator
Method One:
/* Function function: Get parameters from href
*shref:http://www.cscenter.com.cn/arg.htm?arg1=d&arg2=re
*sargname:arg1, Arg2
*return:the value of Arg. D, re
*
/function Getargsfromhref (Shref, Sargname)
{
var args = Shref . Split ("?");
var retval = "";
if (args[0] = = shref)/* parameter is null/
{return
retval; * No processing/
}
var str = args[1];
args = Str.split ("&");
for (var i = 0; i < args.length i + +)
{
str = args[i];
var arg = str.split ("=");
if (arg.length <= 1) continue;
if (arg[0] = = sargname) retval = arg[1];
}
return retval;
}
Method Two:
function GetValue (name)
{
var str=window.location.search;
if (str.indexof (name)!=-1)
{
var pos_start=str.indexof (name) +name.length+1;
var pos_end=str.indexof ("&", Pos_start);
if (pos_end==-1)
{return
str.substring (Pos_start);
}
else
{return
str.substring (pos_start,pos_end)
}
} '
else {return
' does not have this name value ';
}
}
Alert (GetValue (name));
Method Three:
Request = {
querystring:function (item) {
var svalue = Location.search.match (New RegExp ("[\?\&]" + Item + "= ([^\&]*) (\&?) "," I ");
Return svalue? SVALUE[1]: svalue
}
}
Alert (Request.QueryString ("id"));
Method Four:
var Url=location.search;
var Request = new Object ();
if (Url.indexof ("?")! =-1)
{
var str = url.substr (1);//Remove the number
STRs = Str.tolowercase ();
STRs = Strs.split ("&");
for (Var i=0;i<strs.length;i++)
{
request[strs[i].split ("=") [0]]=unescape (Strs[i].split ("=") [1]);
}
var mapwidth = request["W"];
var mapheight = request["H"];
I hope this article will help you with JavaScript programming.