Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo tài liệu 'creating applications with mozilla-chapter 5. scripting mozilla- p4', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Chapter 5. Scripting Mozilla- P4 Figure 5-4. How XPConnect fits into the application model In Mozilla XPConnect is the bridge between JavaScript and XPCOM components. The XPConnect technology wraps natively compiled components with JavaScript objects. XPCOM Mozilla s own cross-platform component technology is the framework on top of which these scriptable components are built. Using JavaScript and XPConnect you can create instances of these components and use their methods and properties as you do any regular JavaScript object as described here. You can access any or all of the functionality in Mozilla in this way. Chapter 8 describes more about the XPConnect technology and how it connects components to the interface. It also describes the components themselves and their interfaces the XPCOM technology and how you can create your own XPCOM components. 5.4.1.1. Creating XPCOM objects in script Example 5-10 demonstrates the creation and use of an XPCOM component in JavaScript. In this example the script instantiates the filepicker object and then uses it to display a file picker dialog with all of the file filters selected. To run this example add the function to your xfly.js file and call it from an event handler on the New menu item you added in Example 3-5. Example 5-10. Scriptable component example chooseApp Open file picker and prompt user for application. chooseApp function var nsIFilePicker Components.interfaces.nsIFilePicker var fp Components.classes @mozilla.org filepicker 1 . createInstance nsIFilePicker fp.init this.mDialog this.getString chooseAppFilePickerTitle nsIFilePicker.modeOpen fp.appendFilters nsIFilePicker.filterAll if fp.show nsIFilePicker.returnOK fp.file this.choseApp true this.chosenApp fp.file Update dialog. this.updateApplicationName this.chosenApp.unicodePa th Note the first two lines in the function and the way they work together to create the fp filepicker object. The first line in the function assigns the name of the nsFilepicker .