检测文件是否已在 javascript/hta 中打开
我正在尝试修复我公司某人三四年前创建的 .hta。 现在,如果您打开其他人已经打开的文件,您将丢失对其所做的所有工作,并且必须重新手动操作。 所以我想只是检查文件是否已经打开,然后锁定编辑,或者只是制作一个弹出窗口说“嘿,如果你尝试保存你会失望的”。 有没有一种简单的方法来检查文件是否已经在 JavaScript 中打开?
打开文件的代码是...
function FileOpen( strSetup )
{
if( ! strSetup )
{
strSetup = ShowDialog( "choose-setup", {"DialogTitle" : "Load Setup"} );
}
if( strSetup )
{
if( FileSystem.FileExists( App.Paths.Configs + "/" + strSetup + ".setup" ) )
{
var fFile = FileSystem.GetFile( App.Paths.Configs + "/" + strSetup + ".setup" );
App.Config = LoadXMLDocument( fFile.Path );
// SaveCurrentConfig();
RefreshView( "setup-summary" );
}
else
{
alert( "Could not find setup '" + strSetup + "'" );
}
}
}
而 LoadXMLDocument 的代码是...
//-----------------------------------------------------------------------------
// FUNCTION : LoadXMLDocument - Loads an XML document
// params : strPath - the path/file of the document to load
// : bCritical- if set true, we die if the document doesn't load
// returns : an XML dom object on success, false otherwise
//-----------------------------------------------------------------------------
function LoadXMLDocument( strPath, bCritical )
{
var xmlDoc = new ActiveXObject( "Msxml2.DOMDocument.3.0" );
xmlDoc.setProperty( "SelectionLanguage", "XPath" );
if( ! FileSystem.FileExists( strPath ) )
{
Error( "'" + strPath + "' is not a valid file path" );
if( bCritical ) Abort();
return( false );
}
var fFile = FileSystem.GetFile( strPath );
xmlDoc.load( fFile.Path );
if( xmlDoc.documentElement == null )
{
Error( "Could not load XML document '" + fFile.Path + "'" );
if( bCritical ) Abort();
return( false );
}
return( xmlDoc );
}
I'm trying to fix a .hta that someone at my company created 3 or 4 years ago. Right now if you open a file that someone else already has open, you'll lose any work you've done on it and will have to manually do it over again. So I was thinking just checking to see if the file is already open and then either locking editing, or just making a popup saying "hey, if you try to save you're gonna be disappointed". Is there an easy way to check to see if the file is already open in javascript?
The code to open the file is...
function FileOpen( strSetup )
{
if( ! strSetup )
{
strSetup = ShowDialog( "choose-setup", {"DialogTitle" : "Load Setup"} );
}
if( strSetup )
{
if( FileSystem.FileExists( App.Paths.Configs + "/" + strSetup + ".setup" ) )
{
var fFile = FileSystem.GetFile( App.Paths.Configs + "/" + strSetup + ".setup" );
App.Config = LoadXMLDocument( fFile.Path );
// SaveCurrentConfig();
RefreshView( "setup-summary" );
}
else
{
alert( "Could not find setup '" + strSetup + "'" );
}
}
}
and the code for LoadXMLDocument is...
//-----------------------------------------------------------------------------
// FUNCTION : LoadXMLDocument - Loads an XML document
// params : strPath - the path/file of the document to load
// : bCritical- if set true, we die if the document doesn't load
// returns : an XML dom object on success, false otherwise
//-----------------------------------------------------------------------------
function LoadXMLDocument( strPath, bCritical )
{
var xmlDoc = new ActiveXObject( "Msxml2.DOMDocument.3.0" );
xmlDoc.setProperty( "SelectionLanguage", "XPath" );
if( ! FileSystem.FileExists( strPath ) )
{
Error( "'" + strPath + "' is not a valid file path" );
if( bCritical ) Abort();
return( false );
}
var fFile = FileSystem.GetFile( strPath );
xmlDoc.load( fFile.Path );
if( xmlDoc.documentElement == null )
{
Error( "Could not load XML document '" + fFile.Path + "'" );
if( bCritical ) Abort();
return( false );
}
return( xmlDoc );
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是修订控制的全部内容。 这与不涉及的同一问题的其他形式没有什么不同。 hta 文件。
That's what revision control is all about. It's no different than other forms of the same issue that does not involve. hta files.
我看到这是一个非常旧的帖子,但为什么不使用 VBS 呢? 如果是 HTA,则支持它们一起运行:
I see this is super old post but why not use VBS? If it's an HTA, they're supported with running together: