【问题标题】:Setting cookies for web view winjs为 web 视图 winjs 设置 cookie
【发布时间】:2013-09-09 10:17:18
【问题描述】:

所以我在我的 Metro 应用程序中使用 x-ms-webview(使用 HTML/JavaScript)并且需要启用/设置 cookie。我尝试设置 document.cookie 字段但没有成功。这样做的正确方法是什么?

【问题讨论】:

  • 我相信它们在不同的安全区域运行,所以你不能那样做。您无法安全地托管来自不同区域的网页并设置 cookie。 WebView 只是一个 iframe。所以,这个 (en.wikipedia.org/wiki/Same_origin_policy) 适用。
  • 我导航到的 url 来自我的应用数据,所以我认为这里没有不同的安全区域。
  • x-ms-webview 中的src 是什么?
  • 我正在使用 webview.navigate("ms-appdata:///local/filename")
  • 我不确定它对你有多大帮助。[blogs.msdn.com/b/wsdevsol/archive/2012/10/18/…] 看看7.如何清除WebView缓存

标签: html webview microsoft-metro winjs


【解决方案1】:
var webview = element.querySelector("x-ms-webview");
var httpRequestMessage = new Windows.Web.Http.HttpRequestMessage(
      Windows.Web.Http.HttpMethod.get,
      new Windows.Foundation.Uri("www.sample.com"));
// ... more settings

httpRequestMessage.headers.cookie.tryParseAdd("a=b;c=d;");

webview.navigateWithHttpRequestMessage(httpRequestMessage);

通常 tryParseAdd(string) 就足够了,转到http://msdn.microsoft.com/en-us/library/windows/apps/windows.web.http.httprequestmessage.aspx 了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-26
    • 1970-01-01
    • 1970-01-01
    • 2015-06-28
    • 2020-05-30
    • 1970-01-01
    相关资源
    最近更新 更多