如何在我的主hta中编写子hta,以便sub隐藏在主hta中,当单击主hta的按钮时,sub应该会弹出,就像窗口一样。
我不想将这些主和子hta作为两个单独的文件来编程,并从主hta调用sub。
发布于 2013-09-18 18:58:13
有一种方法,-that,我可以想到-这样做,但它真的很痛苦。和提穆提到的一样。但是,如果您坚持使用单个hta文件,下面是您的代码:
<html>
<head>
<title>Main HTA</title>
<HTA:APPLICATION
SCROLL="no"
INNERBORDER="no"
/>
</head>
<body>
This is the main HTA <br /><br />
<input type="button" value="open sub hta" onclick="runSubHTA(subhta)" />
<script type="text/javascript">
// path to the new (sub) hta file
var subhta = "subhta.hta";
// function to create and launch the sub hta file
function runSubHTA(path) {
// creating the new hta file
var fso = new ActiveXObject("Scripting.FileSystemObject");
var sub = fso.CreateTextFile(subhta, true);
// writing to the created hta file
sub.WriteLine("<title>Sub HTA<\/title>");
sub.WriteLine("Welcome to the sub HTA <br />");
// this code will run on the sub hta before exit
// and it'll delete the sub hta file, meaning itself
sub.WriteLine('<script type="text/javascript">');
sub.WriteLine('var subhta = "subhta.hta";');
sub.WriteLine('window.onbeforeunload = function() {');
sub.WriteLine('var fso = new ActiveXObject("Scripting.FileSystemObject");');
sub.WriteLine('var sub = fso.DeleteFile(subhta, 1);');
sub.WriteLine('}<\/script>');
// closing the connection to the file, we're done writing
sub.Close();
// launching the sub hta file
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run(path, 1, false);
}
</script>
</body>
</html>编写2个单独的hta文件要容易得多。这样,您就必须逐行嵌入您的子hta代码。但也许有更好的方法。就像把整页写成一行,加上换行符和缩进。我以前没试过这样的东西,所以我无法控制。但如果你想办法做到这一点,那就分享吧。
https://stackoverflow.com/questions/18847165
复制相似问题