This Domain(Admin5.com) is for Sale:

Javascript实例教程(19) 使用HoTMetal(5)

时间:2007-10-22  来源:不详  作者:林子


5.怎样编写脚本来检查上次修改的日期

这个On_Document_Activate宏是检查磁盘上的文件是否有与利用HoTMetaL编辑的当前文档相同的上次修改的日期。它提示用户该做什么以防日期不匹配。以下是这个宏的具体代码:

<MACRO name="On_Document_Activate" lang="JScript" id="44" tooltip="Hide_On_Document_Activate"

desc="Runs Macro: Hide_On_Document_Activate"><![CDATA[

// Do this for local documents only

if (ActiveDocument.FullName == ActiveDocument.LocalFullName) {

var name = ActiveDocument.LocalFullName;

if (Application.ReadableFileExists(name)) { // if document has never been saved, do nothing

var fso = new ActiveXObject("Scripting.FileSystemObject");

var f = fso.GetFile(name);

var newMod = Date.parse(f.DateLastModified);

var props = ActiveDocument.CustomDocumentProperties;

if (props.count != 0) {

oldMod = props.Item("LastMod").value;

if (oldMod != newMod) {

var Yes = 6;

var No = 7;

var msg = "The disk version of this document has changed from the";

copyright dedecms



msg = "version in memory. Do you want to re-open the document?";

var ret = Application.MessageBox(msg, 36, "Document Changed");

if (ret == Yes) {

ActiveDocument.Reload();

}

// Reset the timestamp regardless of the user's response

// This will prevent the dialog from always showing

Application.Run("On_Document_Open_Complete");

}

}

}

}

]]></MACRO>

我们再检查文件是否装载了: ActiveDocument.FullName == ActiveDocument.LocalFullName。然后我们验证一下文件是否被保存到磁盘中: Application.ReadableFileExists(name). 类似于前面的On_Document_Open_Complete 宏,我们创建一个ActiveX控件并且提取出文件的上次修改的日期,代码如下:

var fso = new ActiveXObject("Scripting.FileSystemObject");

var f = fso.GetFile(name);

var newMod = Date.parse(f.DateLastModified);
HoTMetal中使用Javascript

5.怎样编写脚本来检查上次修改的日期

接着,我们调用当前文档的定制属性集:props = ActiveDocument.CustomDocumentProperties 并且检查这个属性的数字是否不等于零。我们已经在前面的On_Document_Open_Complete 宏中已经保存了,并将它赋值给oldMod:

看完这篇,您有何感觉呢?

文章评论

共有位Admini5网友发表了评论 查看完整内容

24小时热门信息