Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 = hrefParams.searchParams.get("api"); 

In Firefox and Chrome it works at should and I will get the value of attribute "api".

But in IE I am getting error on console:

SCRIPT445: Object doesn't support this action

Console error debugger points to the problem with line

var hrefParams = new URL(href); 

For solving of another problem I already invoking script

<script type="text/javascript" src="js/bluebird.min.js"></script> 

But it doesn't fix this problem.

Any idea how to fix it in IE?

like image 823
Reddy SK Avatar asked Jan 25 '18 16:01

Reddy SK


1 Answers

At the end I have fixed that by this code:

function getQueryString() {           var key = false, res = {}, itm = null;           // get the query string without the ?           var qs = location.search.substring(1);           // check for the key as an argument           if (arguments.length > 0 && arguments[0].length > 1)             key = arguments[0];           // make a regex pattern to grab key/value           var pattern = /([^&=]+)=([^&]*)/g;           // loop the items in the query string, either           // find a match to the argument, or build an object           // with key/value pairs           while (itm = pattern.exec(qs)) {             if (key !== false && decodeURIComponent(itm[1]) === key)               return decodeURIComponent(itm[2]);             else if (key === false)               res[decodeURIComponent(itm[1])] = decodeURIComponent(itm[2]);           }            return key === false ? res : null; } 

...

        var api = getQueryString('api'); 

I forgot where I found that but it is working as I needed.

like image 129
Reddy SK Avatar answered Sep 17 '22 04:09

Reddy SK