Home  >  Article  >  Web Front-end  >  Detailed introduction to one of the methods of obtaining URL parameters in JavaScript

Detailed introduction to one of the methods of obtaining URL parameters in JavaScript

黄舟
黄舟Original
2017-03-24 14:50:421534browse

This article mainly introduces the JavaScript method of obtaining URL parameters. Has very good reference value. Let’s take a look with the editor

If the address bar URL is: abc.html?m=tomms&c=allsearchlist&pageNo=1&pageNum=20&text=1

<script>
  //Javascript获取url,并把url中的参数变成数组的方法,arr数组的值就是各参数值
  var url = window.document.location.href.toString();
  var u = url.split("?");
  var arr = [];
  if(typeof(u[1]) == "string"){
    u = u[1].split("&");
    for(var i in u){
      var a = (u[i].split("="));
      arr[a[0]] = a[1];
    }
  }
</script>

Note: When the URL contains Chinese characters, the Chinese parameters will be garbled!

The above is the detailed content of Detailed introduction to one of the methods of obtaining URL parameters in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

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