0

サブhtaがメインhtaに隠されるようにメインhtaにサブhtaを書き込む方法と、メインhtaからボタンをクリックすると、サブhtaがウィンドウのようにポップアップするはずです。

これらのメインおよびサブ hta を 2 つの別個のファイルとしてプログラムし、メイン hta からサブ hta を呼び出したくありません。

4

1 に答える 1

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 ファイルをコーディングする方がはるかに簡単です。このように、sub hta コードを 1 行ずつ埋め込む必要があります。しかし、それを行うより良い方法があるかもしれません。改行とインデントを使用して、ページ全体を 1 行で書くようなものです。私はこれまでにこのようなことを試したことがないので、これについては助けられません。しかし、それを行う方法を見つけたら、共有してください。

于 2013-09-18T18:58:13.460 に答える