I am trying to intrgrate my website with Ubuntu Unity as a webapp following the tutorial on the Ubuntu developers site.
So far, I have this code in my HTML document:
<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>
This seems to be working fine. Firefox pops up the message asking if I want to install the web app and I accept it.
Now onto the next bit of the tutorial, I have the following code:
<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>
This also works fine. If I click on "execute" then hello
appears in the log and the notification dialogue pops up in Unity just as it should do.
Now what I want to do is have this execute as soon as the page loads. However, I want to do it on the fly instead of putting it in the OnLoad
of the body tag or anything like that. This is because I will ultimately put it inside a JavaScript conditional statement.
However, I am having trouble getting it to execte at all. Here's my code:
<script type="text/javascript">
notificationExampleOne();
</script>
When I load the page, hello
appears in the log so I know that the function is being executed. However, the second line of the function doesn't appear to execute because the notification does not display in Unity.
I even tried wrapping the function call inside JQuery like this:
<script type="text/javascript">
$(document).ready(function() {
notificationExampleOne();
});
</script>
I get the same result though. The word hello
appears in the log to confirm that the function ran but the Unity notification doesn't fire.