在单个hta中编写2个hta程序并调用sub hta作为新窗口

时间:2013-09-17 10:17:24

标签: hta

如何在我的主hta中编写sub hta,以便sub hta隐藏在主hta中,当点击主hta中的按钮时,sub hta应该像窗口一样弹出。

我不想将这些主要和子hta编程为2个单独的文件,并从主要的hta调用sub hta。

1 个答案:

答案 0 :(得分:0)

有一种方法 - 我能想到 - 做到这一点,但它真的很痛苦。和Teemu提到的方式相同。但是如果你坚持使用单个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代码。但可能有更好的方法来做到这一点。就像用一行换行和缩进将整个页面写成一行一样。我之前没有尝试过这样的事情所以我无法帮助解决这个问题。但是如果你找到了办法,那就分享吧。

相关问题