hotmetal中使用javascript
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\n";
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);
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器