我学习了如何将 HTML 页面嵌入到 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>
提前致谢。