Receive the parameters in the address bar in HTML

xiaoxiao2021-03-06  50

Receive the parameters in the address bar in HTML

Today, I encountered a problem in the work, just to receive the parameters in the address bar in the HTML file, I have received parameters in the ASPX, as long as the Request [parameter name] is in line, it will be resolved under the help of netizens. Although it is not solved by yourself, you have learned something.

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 get the back parameters

// PARAM is the name of the parameter 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);

Return Query.substring (iStart, IEND);

Then call the GetParameter method: var temp = getParameter ("aa");

2. Use window.location.href to get the back parameters

Var URL = window.location .href; var aa = url.indexof ('=');

IF (aa == -1) Return ""

URL = url.substring (aa 1); Window.alert (URL);

Two ways actually think, using the indexof attribute of the string to take the value.

转载请注明原文地址:https://www.9cbs.com/read-117101.html

New Post(0)