I encountered a problem at work today, which is to receive parameters in the address bar in an html file. In the past, parameters were received in aspx. Just use request [parameter name]. Later, it was solved with the help of netizens. Although I didn't solve it myself, I learned something from it. window.open ("11.htm?aa="+dd);The problem is to receive the value of aa from 11.htm The solution is as follows: 1. Use window.location.search to obtain the following parameters // param is the name of the parameter return query.substring(iStart, iEnd); Then call the getParameter method: var temp = getParameter("aa"); 2. Use window.location.href to obtain the following parameters var url=window.location .href; if (aa == -1) url=url.substring(aa+1); The two methods actually have the same idea, using the indexOf attribute of the string to get the value.
function getParameter(param)
{
var query = window.location.search;
var iLen = param.length;
var iStart = query.indexOf(param);
if (iStart == -1)
return "";
iStart += iLen + 1;
var iEnd = query.indexOf("&", iStart);
if (iEnd == -1)
return query.substring(iStart);
}
var aa=url.indexOf('=');
return "";
window.alert(url);