下面是个简单易学的Javascript实例教程(20-10)教程,图老师小编详细图解介绍包你轻松学会,喜欢的朋友赶紧get起来吧!
【 tulaoshi.com - Web开发 】
HoTMetal中使用JavaScript
5.怎样编写脚本来检查上次修改的日期
这个On_Document_Activate宏是检查磁盘上的文件是否有与利用HoTMetaL编辑的当前文档相同的上次修改的日期。它提示用户该做什么以防日期不匹配。以下是这个宏的具体代码:
desc="Runs Macro: Hide_On_Document_Activate"
// 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;
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)if (oldMod != newMod) {
var Yes = 6;
var No = 7;
var msg = "The disk version of this document has changed from the";
msg += "version in memory. Do you want to re-open the document?";
var ret = Application.MessageBox(msg, 36, "Document Changed");
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)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");
}
}
}
}
]]
我们再检查文件是否装载了: 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);
来源:http://www.tulaoshi.com/n/20160219/1628019.html
看过《Javascript实例教程(20-10)》的人还看了以下文章 更多>>