javascript - 如何从 HTML 页面访问 Gnome 应用程序 JavaScript 函数?

标签 javascript html gtk gnome-3

我了解到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/

相关文章:

javascript - XMLHttpRequest 在 IE11 上很奇怪,在 Edge 和 Chrome 上没问题

javascript - 在全站范围内查找元素索引

gtk - Lisp 中的指针?

c - 为 gtk_overlay 添加背景颜色

javascript - CanJS 模型 : attr function and nested data

javascript - jQuery:满足条件后更改类

html - CSS - 显示 :none on hover self

html - 如何清理 DotNetNuke 页面以便在移动设备上查看?

c - 向 SDL 添加菜单,同时保持跨平台兼容

Javascript Canvas 问题 : Why do my points on the canvas not correspond properly to the height of the graph?