'Get Query Params in IE 11
This function errors out in IE 11 but works with other browsers. I expect params to be something like params = {user: 123} if URL is http://example.com/?user=123.
let params = {};
window.location.href.replace(
/[?&]+([^=&]+)=([^&]*)/gi,
(_, key, value) => (params[key] = value)
);
Solution 1:[1]
Because IE 11 does not support the arrow function syntax, you have to[1] replace that code with the equivalent that has an explicit callback function
var params = {};
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
function(_, key, value) {
return params[key] = value;
});
As griest mentions in a comment, to be safe you should use decodeURIComponent on the href, so that line becomes
decodeURIComponent(window.location.href).replace(/..etc../,
[1] "have to", unless you are in the fortunate position of just declaring that you don't support Internet Explorer.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
