IE中window.URL的替代方案是什么?

Ste*_*rov 5 javascript url internet-explorer

我现在使用window.URL对象来处理url:

var url = new window.URL(text);
return url.host + url.pathname;
Run Code Online (Sandbox Code Playgroud)

但看起来IE并不完全支持它.

你能推荐什么通用解决方案?

Eua*_*ith 2

我使用 Steven Levithan 的 parseURI.js:http ://blog.stevenlevithan.com/archives/parseuri

它虽小但很全面。要使用它来完成与您的代码片段相同的工作:

var url = parseUri(text);
return url.host + url.path;
Run Code Online (Sandbox Code Playgroud)