new URL(location.href) doesn't work in IE

后端 未结 9 1625
心在旅途
心在旅途 2020-12-10 23:52

I am facing to problem with method new URL(\'address\') in IE.

I have this code:

var href =  location.href;
var hrefParams = new URL(href);
var api =         


        
9条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 00:55

    modified @ales code for getting the value of a particular parameter. The default value is set to false.

    function getUrlVars(index) {
      var vars = {};
      window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (
        m,
        key,
        value
      ) {
        vars[key] = value;
      });
    
      if (index) {
        return vars[index] || false;
      }
      return vars;
    }
    

提交回复
热议问题