Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

jquery - SCRIPT5009: 'URLSearchParams' is undefined in IE 11

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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&param2=&id=6"

$.urlParam('param1');  // name
$.urlParam('id');      // 6
$.urlParam('param2');  // null

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...