【问题标题】:python webkitgtk xmlhttprequest file protocolpython webkitgtk xmlhttprequest 文件协议
【发布时间】:2011-08-28 17:17:09
【问题描述】:

如何在pywebkit中为file://协议启用xmlhttprequest?

就像 chrome 一样

http://www.google.com/support/forum/p/Chrome/thread?tid=171316324d16747b&hl=en

【问题讨论】:

    标签: python webkit gtk xmlhttprequest file-uri


    【解决方案1】:

    WebView 上设置enable-file-access-from-file-uris 属性:

    view = webkit.WebView()
    settings = view.get_settings()
    settings.set_property('enable-file-access-from-file-uris', 1)
    view.open('file://./foo.html')
    

    示例文件foo.htmlfile://./bar.html 的内容写入正文:

    <html>
    <head><script type="text/javascript" src="jquery-1.4.4.js"></script></head>
    <body><script>
    $.ajax({url: 'file://./bar.html', success: function(data) {
        document.write(data);
        }
    });
    </script></body></html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多