简体   繁体   English

XUL未引用JavaScript文件

[英]XUL not referencing javascript file

My XUL application has an external javascript file which defines some functions. 我的XUL应用程序有一个定义了某些功能的外部javascript文件。 These functions were previously working, but now I can't call any of these functions from within the .xul file. 这些功能以前可以使用,但是现在我无法从.xul文件中调用任何这些功能。 Can anyone see what I've done wrong? 谁能看到我做错了什么?

Here's the chrome.manifest file 这是chrome.manifest文件

content mac chrome/content/
skin    mac classic/1.0 chrome/skin/

Here's the very top of my main.xul file 这是我的main.xul文件的最顶部

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://mac/skin/main.css" type="text/css"?>

<window id="mac-window" 
    title="MAC" 
    persist="screenX screenY width height sizemode"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <script type="text/javascript" src="chrome://mac/content/main.js"/>

Note that the css file referenced at the top of the file works fine. 请注意,在文件顶部引用的css文件可以正常工作。 Also, I've tried changing the "text/javascript" to "application/x-javascript" with no effect. 另外,我尝试将“ text / javascript”更改为“ application / x-javascript”无效。

Here's the entire contents of the javascript file: 这是javascript文件的全部内容:

function exit() {
    window.close();
}

function toggle_toolbar(menuitem, toolbar) {

    switch (menuitem.getAttribute("checked"))
    {
    case "true":
        menuitem.setAttribute("checked", "false");
        toolbar.hidden = true;
        break;
    case "false";
        menuitem.setAttribute("checked", "true");
        toolbar.hidden = false;
        break;
    }
}

These functions get called like this: 这些函数的调用方式如下:

<commandset id="cmdset-file">
    <command id="cmd-toolbar" oncommand="toggle_toolbar(document.getElementById('view-popup-toolbar'), document.getElementById('the-toolbar'));"/>
    <command id="cmd-exit" oncommand="exit();"/>
</commandset>

And two menuitems have the command attribute set to the id of these two commands. 并且两个菜单项的命令属性设置为这两个命令的id。

Javascript put inline in the XUL file work properly, but it seems as if the javascript file cannot be referenced. 内联到XUL文件中的Javascript可以正常工作,但是似乎无法引用Javascript文件。 This worked perfectly fine earlier today. 今天早些时候,这工作得很好。 Before this stopped working, I was experimenting with some javascript to hide/un-hide some tabboxes, but I'm not sure if that's related or not. 在此停止工作之前,我正在尝试一些JavaScript来隐藏/取消隐藏某些选项卡框,但是我不确定是否相关。

Does anyone see why my javascript file has stopped working? 有人看到我的JavaScript文件为什么停止工作了吗?

Thanks in advance! 提前致谢!

EDIT: For clarification, I'm using XULRunner. 编辑:为澄清起见,我正在使用XULRunner。 Also, attempting to call one of the javascript functions from within script tags in the .xul document doesn't work, either. 同样,尝试从.xul文档中的脚本标记内调用javascript函数之一也不起作用。

You should check the Error Console - for a XULRunner app you can access it by specifying the -jsconsole command line flag. 您应该检查错误控制台-对于XULRunner应用程序,您可以通过指定-jsconsole命令行标志来访问它。 You will see this message: 您将看到以下消息:

Exception: missing : after case label 例外:缺少:案例标签后

Referring to this line: 引用此行:

case "false";

There should be a colon at the end of this line, not a semicolon. 该行的结尾应有一个冒号,而不是分号。 Your JavaScript file has a syntax error and that's why it doesn't load. 您的JavaScript文件存在语法错误,这就是为什么它不会加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM