【问题标题】:Write 2 hta program in single hta and call sub hta as new window在单个 hta 中编写 2 个 hta 程序并调用 sub hta 作为新窗口
【发布时间】:2013-09-17 10:17:23
【问题描述】:

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

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

【问题讨论】:

  • 您可以在主HTA中创建一个文件,然后在关闭之前从打开的HTA中删除新创建的文件。

标签: hta


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多