首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在单个hta中编写2个hta程序,并调用sub作为新窗口

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

Stack Overflow用户
提问于 2013-09-17 10:17:23
回答 1查看 2.7K关注 0票数 0

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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-18 18:58:13

有一种方法,-that,我可以想到-这样做,但它真的很痛苦。和提穆提到的一样。但是,如果您坚持使用单个hta文件,下面是您的代码:

代码语言:javascript
复制
    <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代码。但也许有更好的方法。就像把整页写成一行,加上换行符和缩进。我以前没试过这样的东西,所以我无法控制。但如果你想办法做到这一点,那就分享吧。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18847165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档