Mozilla Firefox扩展(Extensions)开发——xulrunner

XULRunner is a Mozilla runtime package that can be used to bootstrap XUL+XPCOM applications that are as rich as Firefox and Thunderbird. It provides mechanisms for installing, upgrading, and uninstalling these applications. XULRunner also provides libxul, a solution which allows the embedding of Mozilla technologies in other projects and products.

关于XULRunner的介绍:https://developer.mozilla.org/en-US/docs/Mozilla/Projects/XULRunner

下面介绍XULRunner开发一个桌面应用的例子:《Getting statred wiht XULRunner》

Step1:下载XULRunner

下载地址:http://ftp.mozilla.org/pub/xulrunner/releases/latest/

Step2:安装XULRunner

windows下解压放在固定目录即可,例如:C:\program files\xulrunner

Setp3:创建应用目录结构 

+ myapp/
|
+-+ chrome/
| |
| +-+ content/
| | |
| | +-- main.xul
| | |
| | +-- main.js
| |
| +-- chrome.manifest
|
+-+ defaults/
| |
| +-+ preferences/
|   |
|   +-- prefs.js
|
+-- application.ini
|
+-- chrome.manifest

 Step4:配置Application.ini

[App]
Vendor=XULTest
Name=myapp
Version=1.0
BuildID=20100901
[email protected]

[Gecko]
MinVersion=1.8
MaxVersion=200.*
Step5:配置Chrome manifest

chrome/chrome.manifest

content myapp content/
根目录下的 chrome.manifest
manifest chrome/chrome.manifest

Step6:配置Preference

prefs.js

pref("toolkit.defaultChromeURI", "chrome://myapp/content/main.xul");

/* debugging prefs, disable these before you deploy your application! */
pref("browser.dom.window.dump.enabled", true);
pref("javascript.options.showInConsole", true);
pref("javascript.options.strict", true);
pref("nglayout.debug.disable_xul_cache", true);
pref("nglayout.debug.disable_xul_fastload", true);
Step7:配置XUL

main.xul

<?xml version="1.0"?>

<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window id="main" title="My App" width="300" height="300" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="application/javascript" src="chrome://myapp/content/main.js"/>

  <caption label="Hello World"/>
  <separator/>
  <button label="More >>" oncommand="showMore();"/>
  <separator/>
  <description id="more-text" hidden="true">This is a simple XULRunner application. XUL is simple to use and quite powerful and can even be used on mobile devices.</description>

</window>
main.js

function showMore() {
  document.getElementById("more-text").hidden = false;
}
Step8:运行application

运行命令:xulrunner.exe application.ini

注意考虑路径。

运行截图:

Mozilla Firefox扩展(Extensions)开发——xulrunner_第1张图片



你可能感兴趣的:(Mozilla Firefox扩展(Extensions)开发——xulrunner)