JavaScript not executing inside xul file
I am having trouble writing js in a XUL file. I have written a simple method inside xul but it doesn't execute when you open the browser.
This is the method inside the xul tag:
function demo() {
alert('hello');
}
I ve tried to change the tag of the script from <script>
to <html:script>
but still method doesn't work. I tried开发者_C百科 to use methods from external js file using <html:script type="application/x-javascript" src="overlay.js">
still not working.
The name of the xul file is ff-sidebar.xul
. Basically what I am trying to do is display text on the sidebar using javascript functions that are in external js files. I really need javascript to work inside xul file so I can use the js methods. I know for sure that nothing is wrong with the js file.
I think you have an addressing problem in your JavaScript reference. I believe Firefox is not able to locate overlay.js. Try this:
<script type="application/javascript" src="chrome://sidebar/content/overlay.js">
where "sidebar" is the name of your app, and your .js file is located in the "sidebar/chrome/content" directory, alongside your sidebar.xul file.
More information on the chrome URL can be found here.
精彩评论