当我调用webkit_web_view_load_string()将html内容加载到webkitview中时,webkit总是拒绝加载html内容中引用的本地文件或资源(css、javascript、图像)。
注意:我使用GResource将资源加载到二进制文件中。这不是一个例子:
GBytes *data;
GResource *resource;
GByteArray* gbarray; resource = one_file_get_resource();
.。。。
g_resources_register (resource);
data = g_resource_lookup_data (resource,"/com/test/resources/index.html", G_RESOURCE_LOOKUP_FLAGS_NONE,NULL);
gbarray = g_bytes_unref_to_array(data);
const gchar* data_char = gbarray->data;。。。
webkit_web_view_load_string(webView, data_char, NULL, NULL,"");这是我的GResources的xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/com/test">
<file>resources/index.html</file>
<file>resources/style.css</file>
</gresource>
</gresources>现在我的问题是index.html已经加载,但是没有css文件。我得到了我的html文件没有样式!!我怎么才能解决这个问题,谢谢?!
发布于 2012-06-28 22:08:09
您应该以某种方式告诉WebKit,加载本地资源是可行的。您可以通过使用webkit_web_view_load_uri并确保使用file:// URI来完成此操作。否则,WebKit将假定字符串(在load_string中)来自不受信任的来源,因此不允许访问本地资源。
https://stackoverflow.com/questions/11245511
复制相似问题