SCRIPT5009:在IE 11中未定义"URLSearchParams" [英] SCRIPT5009: 'URLSearchParams' is undefined in IE 11

查看:576
本文介绍了SCRIPT5009:在IE 11中未定义"URLSearchParams"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行 URLSearchParams ,但是我由于IE 11不支持,因此在IE 11上显示错误.它可以在Chrome和Firefox中完美运行.

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.

如何在IE 11中获得等效功能? 我正在Laravel 5.4中执行代码.

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);

错误:

SCRIPT5009:"URLSearchParams"未定义

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;
    }
}

例如"example.com?param1=name&param2=&id=6"

So for example "example.com?param1=name&param2=&id=6"

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

这篇关于SCRIPT5009:在IE 11中未定义"URLSearchParams"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆