@bigfishtv/cockpit
Version:
24 lines (20 loc) • 792 B
JavaScript
const originAnchor = document.createElement('a')
originAnchor.href = window.location.href
// from jquery source code
export default function isCrossDomain(url) {
const 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
}
}