【发布时间】:2016-05-02 00:42:05
【问题描述】:
以下是我正在加载到 Microsoft Edge 中的本地文件的精简版本:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script>
var url = "http://example.com"
// Document is ready
ready(function () {
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true)
xhr.withCredentials = true
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8")
xhr.onload = function() {
console.log('onload')
console.log('Status: ' + xhr.status + ". " + xhr.statusText)
}
xhr.onerror = function(error) {
console.log('onerror')
}
xhr.send()
})
// Hook for when the DOM has finished loading
function ready(fn) {
if (document.readyState !== 'loading') {
fn()
} else {
document.addEventListener('DOMContentLoaded', fn)
}
}
</script>
</head>
<body>
</body>
</html>
使用file:///path/to/file.html 将其加载到浏览器中效果很好,并且请求成功返回。我遇到的问题是响应应该在浏览器中设置一个 cookie。它可以在 Chrome、IE11、Firefox 和 Safari 上完美运行,但在 Edge 上却不行。
是否有某种安全措施可以防止 Edge 从本地文件运行的 JavaScript 创建 cookie?如果有,为什么?
【问题讨论】:
-
看起来如果您无法从另一个域创建 cookie.. 只是一个安全策略?
-
我不这么认为,因为如果我运行从本地主机托管的文件,或者通过控制台在任何其他网页上运行脚本,它会完美运行。
-
我有同样的问题 - 我发出一个 ajax 请求,响应包含一个 cookie。此 cookie 未保存在 Edge 中,但保存在 Chrome 和 Firefox 中
标签: javascript ajax cookies microsoft-edge