0

How to write sub hta in my main hta so that the sub hta is hidden in main hta and when clicking a button from main hta, the sub hta should pop up just like a window.

I don't want to program these main and sub hta's as 2 separate files and call sub hta from main hta.

4

1 回答 1

0

有一种方法——我能想到——可以做到这一点,但这真的很痛苦。就像提姆提到的那样。但是,如果您坚持使用单个 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 文件会容易得多。这样,您必须逐行嵌入您的 sub hta 代码。但可能有更好的方法来做到这一点。就像用换行和缩进将整个页面写在一行中一样。我以前没有尝试过这样的事情,所以我对此无能为力。但是,如果您找到了方法,请分享。

于 2013-09-18T18:58:13.460 回答