开发者

Referencing an id from separate XUL files

开发者 https://www.devze.com 2023-04-07 01:13 出处:网络
If I have two different XUL files, is it possible for the javascript in one to reference a XUL id that is defined in the other? I want to use javascript in a separate xul file to edit the XU开发者_如何

If I have two different XUL files, is it possible for the javascript in one to reference a XUL id that is defined in the other? I want to use javascript in a separate xul file to edit the XU开发者_如何学编程L in another one.


You can do reference any JS files inside a XUL file & It will be the same If you want to the same JS files in another XUL file.

For example:

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin/" ?>
<?xml-stylesheet type="text/css"href="chrome://hello/skin/browserOverlay.css" ?>

<!DOCTYPE overlay SYSTEM
  "chrome://hello/locale/browserOverlay.dtd">

<overlay id="xulschoolhello-browser-overlay"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="application/x-javascript"
    src="chrome://hello/content/browserOverlay.js" />
    <script type="application/x-javascript" src="chrome://hello/content/javaLoader.js" />
    <script type="application/x-javascript" src="chrome://hello/content/window.js" />

</overlay>

If you want to use JS inside XUL, it's possible but in this case you can't link this JS functions to another XUL.

Type this inside the XUL file:

<script type="application/x-javascript">
<![CDATA[
    // your code here
]]>
</script>

I would recommend to use JS files separately & you can link them to any number of XUL files as I explained above.

References : https://developer.mozilla.org/en/Building_an_Extension https://developer.mozilla.org/en/Setting_up_extension_development_environment


What you seem to be looking for are XUL overlays. These overlays can be registered in your chrome.manifest file and will allow applying modifications to other XUL documents. For example, most Firefox extensions register an overlay for chrome://browser/content/browser.xul (the main browser window).

0

精彩评论

暂无评论...
验证码 换一张
取 消