@bigfishtv/cockpit
Version:
23 lines (20 loc) • 794 B
JavaScript
var originAnchor = document.createElement('a');
originAnchor.href = window.location.href;
// from jquery source code
export default function isCrossDomain(url) {
var urlAnchor = document.createElement('a');
// Support: IE <=8 - 11, Edge 12 - 15
// IE throws exception on accessing the href property if url is malformed,
// e.g. http://example.com:80x/
try {
urlAnchor.href = url;
// Support: IE <=8 - 11 only
// Anchor's host property isn't correctly set when s.url is relative
urlAnchor.href = urlAnchor.href;
return originAnchor.protocol + '//' + originAnchor.host !== urlAnchor.protocol + '//' + urlAnchor.host;
} catch (e) {
// If there is an error parsing the URL, assume it is crossDomain,
// it can be rejected by the transport if it is invalid
return true;
}
}