1

我学习了如何将 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>

提前致谢。

4

1 回答 1

2

You can't use GTK APIs from inside the JS inside the HTML. You'll have to set up some method of communication between the two. For example, connect to the window-object-cleared signal and set some methods on the window object.

于 2013-01-19T22:33:09.983 回答