javascriptdom-eventsxul

I have js inside xul file and I want to call specific function from the main window


Now I will try to mention my problem:

I have a function called playIt(), inside my Javascript file.

This is the Javascript file:

playIt(){
    alert("yes it work!");
}

This Javascript code is inside a XUL file.

And I have this source code:

<html>
<head>
<title>this is title</title>
</head>
<body>
<div id="clickIt" onclick="javascript:playIt();">
</body>
</html>

But the problem is that nothing happens when I click on the div and the function doesn't start.


Solution

  • better way is to attach an event once the content has loaded.

    https://developer.mozilla.org/en/Code_snippets/On_page_load

    after the line // do something with the loaded page.
    add your own code

    doc.getElementById('clickIt').addEventListener('click',playIt,false);
    

    Edit:
    remove the javascript: from the onclick attribute before anything and re-test !!