我了解到how to embedded a HTML page to a gnome JavaScript 应用程序并将其显示在 Gtk+ 框架中。
// Create a webview to show the web app
this._webView = new Webkit.WebView ();
// Put the web app into the webview
this._webView.load_uri (GLib.filename_to_uri (GLib.get_current_dir() +
"/hellognome.html", null));
// Put the webview into the window
this._window.add (this._webView);
// Show the window and all child widgets
this._window.show_all();
现在我要使用 JavaScript 从这个 HTML (hellognome.html) 文件访问 Gtk+ API(比如访问文件系统)或我的 gnome JavaScript 应用程序中的 JavaScript 函数?
像这样的东西:
<html>
<head>
<title>Hello, GNOME!</title>
<!-- Use JavaScript to show a greeting when someone clicks the button -->
<script type="application/javascript">
function greeting () {
document.getElementById ("greeting").innerHTML = ("O hai!");
//// access to a Gtk+ API (like accessing to file system )
or a JavaScript function in my gnome JavaScript application.
}
</script>
</head>
<body>
<br /> <br />
<button type="button" onclick="greeting()">Hello, GNOME!</button>
<!-- Empty H1 element gets filled in when the button is clicked -->
<h1 id="greeting"></h1>
</body>
</html>
提前致谢。
最佳答案
您不能在 HTML 中的 JS 中使用 GTK API。您必须在两者之间设置某种通信方法。例如,连接到 window-object-cleared
发出信号并在窗口对象上设置一些方法。
关于javascript - 如何从 HTML 页面访问 Gnome 应用程序 JavaScript 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14414103/