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

HTML 内の JS 内から GTK API を使用することはできません。2 つの間の通信方法を設定する必要があります。たとえば、window-object-cleared信号に接続し、window オブジェクトにいくつかのメソッドを設定します。

于 2013-01-19T22:33:09.983 に答える