2

我正在尝试按照Ubuntu 开发人员网站上的教程将我的网站与 Ubuntu Unity 集成为 web 应用程序。

到目前为止,我的 HTML 文档中有这段代码:

<script type="text/javascript">
    function unityReady() {
      // Integrate with Unity!
    }
    var Unity = external.getUnityObject(1.0); 

    Unity.init({name: "My WebApp",
                iconUrl: "http://localhost/my-icon.png",
                onInit: unityReady});
</script>

这似乎工作正常。Firefox 弹出消息询问我是否要安装 Web 应用程序并且我接受它。

现在进入教程的下一部分,我有以下代码:

<script type="text/javascript">
    function notificationExampleOne() {
        console.log('hello');
        Unity.Notification.showNotification("This is a test", "New message received", null);
    }
</script>

<a href="javascript:notificationExampleOne()">execute</a>

这也很好用。如果我单击“执行”,则会hello出现在日志中,并且通知对话框会在 Unity 中弹出,就像它应该做的那样。

现在我想做的是在页面加载后立即执行。但是,我想即时进行,而不是将其放在OnLoadbody 标签或类似的东西中。这是因为我最终会将它放在 JavaScript 条件语句中。

但是,我根本无法让它执行。这是我的代码:

<script type="text/javascript">
    notificationExampleOne();
</script>

当我加载页面时,hello出现在日志中,所以我知道该函数正在执行。但是,该函数的第二行似乎没有执行,因为通知未在 Unity 中显示。

我什至尝试将函数调用包装在 JQuery 中,如下所示:

<script type="text/javascript">
    $(document).ready(function() {
        notificationExampleOne();
    });
</script>

我得到了同样的结果。该词hello出现在日志中以确认该功能已运行但 Unity 通知未触发。

4

0 回答 0