MS Edge 不会将从 AJAX 请求返回的 cookie 保存在本地 HTML 文件中

MS Edge won't save cookies returned from AJAX request in local HTML file

以下是我正在加载到 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 和请求 returns 成功将其加载到浏览器中效果很好。我 运行 遇到的问题是响应应该在浏览器中设置一个 cookie。它在 Chrome、IE11、Firefox 和 Safari 上完美运行,但在 Edge 上运行不佳。

是否有某种安全措施可以防止 Edge 从本地文件的 JavaScript(即 运行)创建 cookie?如果是,为什么?

Microsoft Edge 从不保存 javascript 来自

的 cookie
  • 直接打开本地文件,例如file://C:/test/index.html
  • 包含下划线的域,例如test_a.mydomain.com

为了测试 cookie,必须创建一个工作环境,例如localhost@xampp