@@ -41,38 +41,25 @@ import window from 'global/window';
4141 * An object of url details
4242 */
4343export const parseUrl = function ( url ) {
44+ // This entire method can be replace with URL once we are able to drop IE11
45+
4446 const props = [ 'protocol' , 'hostname' , 'port' , 'pathname' , 'search' , 'hash' , 'host' ] ;
4547
4648 // add the url to an anchor and let the browser parse the URL
47- let a = document . createElement ( 'a' ) ;
49+ const a = document . createElement ( 'a' ) ;
4850
4951 a . href = url ;
5052
51- // IE8 (and 9?) Fix
52- // ie8 doesn't parse the URL correctly until the anchor is actually
53- // added to the body, and an innerHTML is needed to trigger the parsing
54- const addToBody = ( a . host === '' && a . protocol !== 'file:' ) ;
55- let div ;
56-
57- if ( addToBody ) {
58- div = document . createElement ( 'div' ) ;
59- div . innerHTML = `<a href="${ url } "></a>` ;
60- a = div . firstChild ;
61- // prevent the div from affecting layout
62- div . setAttribute ( 'style' , 'display:none; position:absolute;' ) ;
63- document . body . appendChild ( div ) ;
64- }
65-
6653 // Copy the specific URL properties to a new object
67- // This is also needed for IE8 because the anchor loses its
54+ // This is also needed for IE because the anchor loses its
6855 // properties when it's removed from the dom
6956 const details = { } ;
7057
7158 for ( let i = 0 ; i < props . length ; i ++ ) {
7259 details [ props [ i ] ] = a [ props [ i ] ] ;
7360 }
7461
75- // IE9 adds the port to the host property unlike everyone else. If
62+ // IE adds the port to the host property unlike everyone else. If
7663 // a port identifier is added for standard ports, strip it.
7764 if ( details . protocol === 'http:' ) {
7865 details . host = details . host . replace ( / : 8 0 $ / , '' ) ;
@@ -86,8 +73,9 @@ export const parseUrl = function(url) {
8673 details . protocol = window . location . protocol ;
8774 }
8875
89- if ( addToBody ) {
90- document . body . removeChild ( div ) ;
76+ /* istanbul ignore if */
77+ if ( ! details . host ) {
78+ details . host = window . location . host ;
9179 }
9280
9381 return details ;
0 commit comments