isCrossOriginUrl.js 864 B

1234567891011121314151617181920212223242526272829
  1. import defined from './defined.js';
  2. var a;
  3. /**
  4. * Given a URL, determine whether that URL is considered cross-origin to the current page.
  5. *
  6. * @private
  7. */
  8. function isCrossOriginUrl(url) {
  9. if (!defined(a)) {
  10. a = document.createElement('a');
  11. }
  12. // copy window location into the anchor to get consistent results
  13. // when the port is default for the protocol (e.g. 80 for HTTP)
  14. a.href = window.location.href;
  15. // host includes both hostname and port if the port is not standard
  16. var host = a.host;
  17. var protocol = a.protocol;
  18. a.href = url;
  19. // IE only absolutizes href on get, not set
  20. a.href = a.href; // eslint-disable-line no-self-assign
  21. return protocol !== a.protocol || host !== a.host;
  22. }
  23. export default isCrossOriginUrl;