Home  >  Article  >  Web Front-end  >  js获取url参数的使用扩展实例_javascript技巧

js获取url参数的使用扩展实例_javascript技巧

WBOY
WBOYOriginal
2016-05-16 19:06:49910browse

最近网站改版,发现网站的广告都是直接网址,如果转向一下,对于本站的全职会好点
需要一个html页面来传递参数所以用到个js获取url参数的代码,就一个funciton
参考http://img.jb51.net/url.htm?url=http://www.baidu.com 

复制代码 代码如下:

<script> <BR>//js获取url参数的function<BR>function request(paras){ <BR>var url = location.href; <BR>var paraString = url.substring(url.indexOf("?")+1,url.length).split("&"); <BR>var paraObj = {} <BR>for (i=0; j=paraString[i]; i++){ <BR>paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf <BR>("=")+1,j.length); <BR>} <BR>var returnValue = paraObj[paras.toLowerCase()]; <BR>if(typeof(returnValue)=="undefined"){ <BR>return ""; <BR>}else{ <BR>return returnValue; <BR>} <BR>} <BR>var theurl <BR>theurl=request("url"); <BR>if (theurl!=''){ <BR>location=theurl <BR>} <BR></script>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn