I'm trying to execute the URLSearchParams but I get an error on IE 11 since it is not supported there. It's working perfectly in Chrome and Firefox.
How can I get the equivalent functionality in IE 11? I am executing the code in Laravel 5.4.
Here is the line of code which I'm trying to execute.
var urlParams = new URLSearchParams(window.location.search);
Error:
SCRIPT5009: 'URLSearchParams' is undefined
Got a solution by replacing the code with the following:
$.urlParam = function(name){
    var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (results == null){
       return null;
    }
    else {
       return decodeURI(results[1]) || 0;
    }
}
So for example "example.com?param1=name¶m2=&id=6"
$.urlParam('param1');  // name
$.urlParam('id');      // 6
$.urlParam('param2');  // null
                        Odhikari's answer as a (partial) polyfill:
(function (w) {
    w.URLSearchParams = w.URLSearchParams || function (searchString) {
        var self = this;
        self.searchString = searchString;
        self.get = function (name) {
            var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(self.searchString);
            if (results == null) {
                return null;
            }
            else {
                return decodeURI(results[1]) || 0;
            }
        };
    }
})(window)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With