今天我读了axios分数并在'isURLSameOrigin.js'中,我看了一些代码,
(function standardBrowserEnv () {
var msie = /(msie|trident)/i.test(navigator.userAgent)
var urlParsingNode = document.createElement('a')
var originURL
function resolveURL (url) {
var href = url
// this is important
if (msie) {
urlParsingNode.setAttribute('href', href)
href = urlParsingNode.href
}
urlParsingNode.setAttribute('href', href)
return {
href: urlParsingNode.href,
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
host: urlParsingNode.host,
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
hostname: urlParsingNode.hostname,
port: urlParsingNode.port,
pathname: (urlParsingNode.pathname.charAt(0) === '/')
? urlParsingNode.pathname
: '/' + urlParsingNode.pathname
}
}
originURL = resolveURL(window.location.href)
return function isURLSameOrigin (requestURL) {
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL
return (parsed.protocol === originURL.protocol &&
parsed.host === originURL.host)
}
})()
它为IE .it setAttribute('href',href)做了两次难度。我只是想知道为什么?这很重要,看起来没用。