$[removed].origin gives wrong value when using IE

前端 未结 2 1550
野的像风
野的像风 2020-12-13 12:15

$window.location.origin returns the wrong value on IE.

The origin property returns the protocol, hostname and port number of a URL.

<
2条回答
  •  情书的邮戳
    2020-12-13 12:56

    You may also need the port number. If so, you can use this polyfill

    if (!window.location.origin) {
      window.location.origin = window.location.protocol + "//" 
        + window.location.hostname 
        + (window.location.port ? ':' + window.location.port : '');
    }
    

    This polyfill is already part of Modernizr.

提交回复
热议问题