/**
*    @Author: Arash Karimzadeh
*    @Email:
*    @Desciption: Here, I post some of my recent
*    researches. Also you can see my code projects.
*/  
Ajax C # Chrome CMS dateNet Design Patterns includeMany JavaScript jBind Joomla jQuery Plugin rails ror RubyOnRails SQLite xul

+ All tags

Content View Hits : 337343
Bookmark and Share
Create xul Application on windows (hello world) PDF Print
Written by Arash Karimzadeh   
Tuesday, 23 June 2009 15:21

Here we will create our first xul application on windows (it is the same in other OS). I expect you know nothing about xul but a bit familiar with javascript, css and xml or html tag format.

first of all download lastest version of xul runner from here or directly from here. At this moment the lastest version is xulrunner-1.9.0.10.en-US.win32.zip. Its important to download the win32 file from runtimes folder not the SDK!

OK now lets try yo create our first xul application:

 

  1. create a folder and name it firstapp.

    I have created it in d:. Now extract the zip file in it, so you will have firstapp>xulrunner folder. Lets extend the firstapp folder and create below structure in it:
    d:\firstapp>
    - xulrunner    \\this folder is createdbyextracting the xulrunner-1.9.0.10.en-US.win32.zip file
    - defaults
    -preferences
    -prefs.js
    -chrome
    -content
    -main.xul
    -chrome.manifest
    application.ini
  2. prefs.js

    This file is the one whom initialize your application so lets define our default page to load by following code. Our default page is main.xul and it is located at firstapp>chrome>content.
    
                      
    1. pref("toolkit.defaultChromeURI", "chrome://firstapp/content/main.xul");
    
                      
     
    
                      
                    

  3. chrome.manifest

    As you see in above code we set the default page path to "chrome://firstapp/content/main.xul". This path must be declared in chrome.manifest by adding the below line to it.
    
                      
    1. content firstapp file:content/
    
                      
     
    
                      
                    

    Whereever we write chrome://firstapp/content/xfile the xulrunner know that it must look inside chrome>content for that xfile.
  4. main.xul

    This is our main page which is located in chrome>content folder. Lets add some content to our main page
    
                      
    1. version="1.0"?>
    2. -stylesheet href="chrome://global/skin/" type="text/css"?>
    3.  
    4. id="main" title="My App" width="300" height="300" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    5.      label="Hello World"/>
    6. >
    
                      
     
    
                      
                    
  5. application.ini

    This file used when running the application to set some default values and information for xulrunner. Add following lines to it:
    
                      
    1. [App]
    2. Vendor=Arash Karimzadeh
    3. Name=First Application
    4. Version=1.0
    5. BuildID=20090622
    6. Copyright=Copyright (c) 2009 Arash Karimzadeh
    7. ID= This e-mail address is being protected from spambots. You need JavaScript enabled to view it
    8.  
    9. [Gecko]
    10. MinVersion=1.8
    11. MaxVersion=1.9.*
    
                      
     
    
                      
                    

    Change the Vendor and Name to whatever you want.
    *Remember to adjust the MaxVersion with your xulrunner version.
    *ID must be unique for this application. You can read more about it at mozilla website.
  6. xulrunner-stub.exe

    This file is located in xulrunner folder. Copy this file to the firstapp folder and rename it to firstapp.exe. Now you can test what you have done by double clicking on it.
  7. Lets check the folder structure again

    As you see after running the application for the first time to folders are added (extensions and updates).
  8. Add script

    change the main.xul file to below code:
    
                      
    1. version="1.0"?>
    2. -stylesheet href="chrome://global/skin/" type="text/css"?>
    3.  
    4. id="main" title="My App" width="300" height="300" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    5.      src="script.js"/>
    6.      label="Hello World"/>
    7. >
    
                      
     
    
                      
                    

    Also add the script.js file to chrome>content folder and add below line to it
    
                      
    1. alert('hi everybody');
    
                      
     
    
                      
                    
  9. Change style

    Replace the style tag in main.xul with below code
    
                      
    1. -stylesheet href="chrome://firstapp/skin/style.css" type="text/css"?>
    
                      
     
    
                      
                    

    Lets create style.css which contains following code and add it to chrome>skin folder
    
                      
    1. window, caption{
    2.             background: #fff !important;
    3.             color: #ccc;
    4.             font-size: 12px;
    5. }
    
                      
     
    
                      
                    

    also add below line to chrome.manifest file:
    
                      
    1. skin firstapp classic/1.0 file:skin/
    
                      
     
    
                      
                    
  10. Rerun the firstapp.exe

Tags: JavaScript | xul

Last Updated on Sunday, 28 June 2009 09:07