英文:
Change WebKitWebSettings in Go cgo
问题
我正在使用go-webkit,并且我有一个webkitsettings的实例,我该如何更改设置?
我正在尝试像这样做:
main.go
webview := webkit.NewWebView()
settings := webview.GetSettings()
settings.SetEnableJavascript(false)
webview.SetSettings(settings)
go-webkit
来自https://github.com/mattn/go-webkit/blob/master/webkit/webkit.go#L370的代码片段
type WebSettings struct {
glib.GObject
}
func (settings *WebSettings) SetEnableJavascript (flag bool) {
//我尝试了各种方法
//C.g_object_set?
}
func (v *WebView) SetSettings(settings *WebSettings) {
C.webkit_web_view_set_settings(v.getWebView(), C.to_WebKitWebSettings(settings.Object));
}
func (v *WebView) GetSettings() *WebSettings {
return &WebSettings{glib.GObject{unsafe.Pointer(C.webkit_web_view_get_settings(v.getWebView()))}}
}
func NewWebSettings() *WebSettings {
return &WebSettings{glib.GObject{unsafe.Pointer(C.webkit_web_settings_new())}}
}
Webkit API: 1.0
http://webkitgtk.org/reference/webkitgtk/stable/WebKitWebSettings.html
/* 创建一个新的websettings并禁用JavaScript */
WebKitWebSettings *settings = webkit_web_settings_new ();
g_object_set (G_OBJECT(settings), "enable-scripts", FALSE, NULL);
/* 应用结果 */
webkit_web_view_set_settings (WEBKIT_WEB_VIEW(my_webview), settings);
英文:
I'm using go-webkit and I have a instance of webkitsettings, how can I change the settings?
I'm trying to do something like this
main.go
webview := webkit.NewWebView()
settings := webview.GetSettings()
settings.SetEnableJavascript(false)
webview.SetSettings(settings)
go-webkit
Snippet from https://github.com/mattn/go-webkit/blob/master/webkit/webkit.go#L370
type WebSettings struct {
glib.GObject
}
func (settings *WebSettings) SetEnableJavascript (flag bool) {
//I tried various ways
//C.g_object_set?
}
func (v *WebView) SetSettings(settings *WebSettings) {
C.webkit_web_view_set_settings(v.getWebView(), C.to_WebKitWebSettings(settings.Object));
}
func (v *WebView) GetSettings() *WebSettings {
return &WebSettings{glib.GObject{unsafe.Pointer(C.webkit_web_view_get_settings(v.getWebView()))}}
}
func NewWebSettings() *WebSettings {
return &WebSettings{glib.GObject{unsafe.Pointer(C.webkit_web_settings_new())}}
}
Webkit API: 1.0
http://webkitgtk.org/reference/webkitgtk/stable/WebKitWebSettings.html
/* Create a new websettings and disable java script */
WebKitWebSettings *settings = webkit_web_settings_new ();
g_object_set (G_OBJECT(settings), "enable-scripts", FALSE, NULL);
/* Apply the result */
webkit_web_view_set_settings (WEBKIT_WEB_VIEW(my_webview), settings);
答案1
得分: 1
WebSettings
嵌入了glib.GObject
,而glib.GObject
实现了Set
方法(参见godoc)。
所以在你的情况下,g_object_set
应该翻译为settings.GObject.Set
,或者由于GObject
的方法集被导出到WebSettings
,你可以简单地执行以下操作:
settings.Set("enable-scripts", false)
英文:
WebSettings
embeds glib.GObject
which in turn implements the Set
method (see godoc).
So g_object_set
should translate in your case to settings.GObject.Set
or, as the method set
of GObject
is exported to WebSettings
, you can simply do
settings.Set("enable-scripts", false)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论