JavaScript Instance Tutorial (20) using HoTMetaL (6)

Source: Internet
Author: User
Tags add filter
javascript| Tutorial

Using JavaScript in HoTMetaL

6. How to write a save module script

In the example of this tutorial, we created a new Save Module file dialog box. There are several templates in hotmetal that you can choose from. The template is just an ordinary Web page that is saved HoTMetaL the template template in the application directory. When you select a new item from the File menu, one of the label options is page from Template. When you select it, a tabbed dialog box pops up with a variety of templates: general, WebTV, the wide-range, Frame Pages, Layout.

You can create a new template by saving the current file to a directory in the template directory. The following macro, the Save As template, shows you how to create a Save As dialog box using the Hmextras.filedlg Displayfiledlg method. This dialog box uses the template directory as the default location, with the following detailed code:

<macro name= "Save as Template" lang= "JScript" id= "><!" [cdata[

var obj = new ActiveXObject ("Hmextras.filedlg");

var filter = "Web Page Template (*.htm, *.html) |*.htm;*.html| All Files (*.*) |*.*| | ";

if (obj. Displayfiledlg (0, "File Save as", filter, Application.path + "\\Template")) {

Activedocument.saveas (obj. Fullpathname, True); Save and put on recent file list

}

]]></macro>

Let's explain the code above: first, we use the Hmextras Library's Filedlg COM object to create an ActiveX control:

var obj = new ActiveXObject ("Hmextras.filedlg");

Then use several entries to create a filter:

var filter = "Web Page Template (*.htm, *.html) |*.htm;*.html| All Files (*.*) |*.*| | ";

Then we call obj by calling. Displayfiledlg to display the file dialog box, and finally we save the file if the dialog box exists.

Using JavaScript in HoTMetaL

6. How to write a save module script

Let's add the first save as template macro to the File menu. You can click on the File menu bar and choose Custom. Then select the menu tag and navigate to the place where you want to add new macros. Click the Add submenu (Add submenu) button and fill in the missing items. The dialog box is shown in Figure 1.

(Figure 1)

Let's test this menu item and how the macro works. Pull down the File menu, you can see a Save template item, click it, you can get the dialog box as shown in Figure 2:

Find the directory where you want to save the file and give the file name, click the Save button to confirm.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.