For the purposes of my project, I've created this script, which I think also could work for you or someone else who has a problem with IE11 and the lack of support for the URL method.
/* Polyfill URL method IE 11 */
// ES5
if (typeof window.URL !== 'function') {
window.URL = function (url) {
var protocol = url.split('//')[0],
comps = url.split('#')[0].replace(/^(https\:\/\/|http\:\/\/)|(\/)$/g, '').split('/'),
host = comps[0],
search = comps[comps.length - 1].split('?')[1],
tmp = host.split(':'),
port = tmp[1],
hostname = tmp[0];
search = typeof search !== 'undefined' ? '?' + search : '';
var params = search
.slice(1)
.split('&')
.map(function (p) { return p.split('='); })
.reduce(function (p, c) {
var parts = c.split('=', 2).map(function (param) { return decodeURIComponent(param); });
if (parts.length == 0 || parts[0] != param) return (p instanceof Array) && !asArray ? null : p;
return asArray ? p.concat(parts.concat(true)[1]) : parts.concat(true)[1];
}, []);
return {
hash: url.indexOf('#') > -1 ? url.substring(url.indexOf('#')) : '',
protocol: protocol,
host: host,
hostname: hostname,
href: url,
pathname: '/' + comps.splice(1).map(function (o) { return /\?/.test(o) ? o.split('?')[0] : o; }).join('/'),
search: search,
origin: protocol + '//' + host,
port: typeof port !== 'undefined' ? port : '',
searchParams: {
get: function(p) {
return p in params? params[p] : ''
},
getAll: function(){ return params; }
}
};
}
}
// ES6, in case of using Babel in a project
if( typeof window.URL !== 'function' ){
window.URL = function(url){
let protocol = url.split('//')[0],
comps = url.split('#')[0].replace(/^(https\:\/\/|http\:\/\/)|(\/)$/g, '').split('/'),
host = comps[0],
search = comps[comps.length - 1].split('?')[1],
tmp = host.split(':'),
port = tmp[1],
hostname = tmp[0];
search = typeof search !== 'undefined'? '?' + search : '';
const params = search
.slice(1)
.split('&')
.map(p => p.split('='))
.reduce((obj, pair) => {
const [key, value] = pair.map(decodeURIComponent);
return ({ ...obj, [key]: value })
}, {});
return {
hash: url.indexOf('#') > -1? url.substring(url.indexOf('#')) : '',
protocol,
host,
hostname,
href: url,
pathname: '/' + comps.splice(1).map(function(o){ return /\?/.test(o)? o.split('?')[0] : o; }).join('/'),
search,
origin: protocol + '//' + host,
port: typeof port !== 'undefined'? port : '',
searchParams: {
get: p => p in params? params[p] : '',
getAll: () => params
}
};
}
}
/* Polyfill IE 11 end */
new URL('http://localhost:8080/?a=1&b=3&c=z#123').searchParams.get('c'); // this will return "z"
But if it doesn't work for you, you could take I think full suported and polifilled function from this package here on the url:
https://www.npmjs.com/package/url-polyfill
window.URL
is only available in Edge (and all other non-IE browsers) – Labiovelar