hta 相关问题

HTML应用程序(HTA)是Microsoft Windows程序,其源代码由HTML,动态HTML和Internet Explorer支持的一种或多种脚本语言(如VBScript或JScript)组成。如果您的问题是关于HTA中的脚本,请始终提及或添加使用的脚本语言的标记。

简单的 javascript 函数可将下一个/上一个 H1 滚动到屏幕顶部 - 在使用 MSHTA.exe 运行的 HTA 应用程序中

我是一名业余程序员,并制作了一个 HTA 文件,其中包含一些 JavaScript 和一个可编辑的内容 。使用最少的 JavaScript,我可以设置键盘快捷键来格式化、保存和退出。 ... 我是一名业余程序员,并且制作了一个 HTA 文件,其中包含一些 JavaScript 和一个可编辑的内容 <DIV>。使用最少的 JavaScript,我可以设置键盘快捷键来格式化、保存和退出。 我正在完全更新的 Windows 10 系统中使用 mshta32.exe 运行该文件。我的空 HTA 只有 12k,为此我可以进行自动换行、格式化、链接图像、打印(包括 PDF)和实时拼写检查!它不是文字处理程序,但对于无干扰的写作,我很喜欢这种体验。 我的下一个目标是使用这些文件进行演示;我需要的最少功能是“下一张幻灯片”和“上一张幻灯片”快捷方式。使用 <H1> 标签作为幻灯片标题似乎是合理的,因此我的快捷方式只需要滚动,以便下一个或上一个 <H1> 位于屏幕顶部(是的,HTA 确实以大写形式保存标签)。 在互联网/ChatGPT 上有使用 document.querySelector 的解决方案,但这似乎在 HTA/MSHTA 中不受支持(我尝试过使用 content=ie=edge 和 http-equiv=X-UA-Compatible 的元标记)。不热衷于 JQuery,因为这是一个极简主义项目,需要离线工作,所以我尝试用 jQuery 翻译一个建议: 制作一个滚动到下一个标题的跳过按钮 $('html, body').scrollTop($(this).nextInDOM($('h1, h2, h3, h4, h5, h6')).position().top); event.preventDefault(); 至 JavaScript: document.querySelector('html, body').scrollTop(document.querySelector(this).nextInDOM(document.querySelector('h1, h2, h3, h4, h5, h6')).position().top); event.preventDefault(); 这不起作用!欢迎任何指导。 亲切的问候加文霍尔特 整个HTA <!DOCTYPE html> <HTML> <HEAD unselectable="on"> <TITLE unselectable="on"> ContentEditor - O:\MyProfile\editor\templates\default.hta</TITLE><?XML:NAMESPACE PREFIX = "HTA" /> <HTA:Application id=document.currentScript VERSION="2" SYSMENU="yes" Singleinstance="no" ShowInTaskBar="yes" scroll="yes" NAVIGABLE="yes" MinimizeButton="yes" MaximizeButton="yes" Icon="O:\MyProfile\cmd\IcoFX\ContentEditor.ico" ContextMenu="No" Border="No" APPLICATIONNAME="MSI-BUILD"></HTA:Application> <BASE target=_blank unselectable="on"> <META name=viewport content="width=device-width, initial-scale=1" unselectable="on"> <META content=ie=edge unselectable="on"> <META http-equiv=X-UA-Compatible unselectable="on"> <STYLE unselectable="on"> @media Unknown { .sidenav { PADDING-TOP: 15px } } HTML { COLOR: #657b83; MARGIN: 1em; BACKGROUND-COLOR: #fdf6e3 } BODY { FONT-SIZE: 24px; FONT-FAMILY: Helvetica, arial, sans-serif; LETTER-SPACING: 0px; BACKGROUND-COLOR: #fdf6e3 } .sidenav { FONT-SIZE: 22px; OVERFLOW: hidden; HEIGHT: 100%; WIDTH: 0px; OVERFLOW-X: hidden; POSITION: fixed; PADDING-TOP: 4px; LEFT: 0px; Z-INDEX: 1; TOP: 0px; BACKGROUND-COLOR: #111; transition: 0.5s } .sidenav A { TEXT-DECORATION: none; COLOR: #818181; PADDING-BOTTOM: 8px; PADDING-TOP: 8px; PADDING-LEFT: 32px; DISPLAY: block; PADDING-RIGHT: 8px; transition: 0.3s } .sidenav P { COLOR: #818181; PADDING-BOTTOM: 4px; PADDING-TOP: 8px; PADDING-LEFT: 4px; PADDING-RIGHT: 4px } TD { COLOR: #818181; PADDING-BOTTOM: 4px; PADDING-TOP: 8px; PADDING-LEFT: 4px; PADDING-RIGHT: 4px } TH { COLOR: #818181; PADDING-BOTTOM: 4px; PADDING-TOP: 8px; PADDING-LEFT: 4px; PADDING-RIGHT: 4px } B { COLOR: #818181; PADDING-BOTTOM: 4px; PADDING-TOP: 8px; PADDING-LEFT: 4px; PADDING-RIGHT: 4px } U { COLOR: #818181; PADDING-BOTTOM: 4px; PADDING-TOP: 8px; PADDING-LEFT: 4px; PADDING-RIGHT: 4px } .sidenav A:hover { COLOR: #f1f1f1 } .sidenav TABLE { BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; LINE-HEIGHT: 1; BORDER-TOP-WIDTH: 0px } TR { BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; LINE-HEIGHT: 1; BORDER-TOP-WIDTH: 0px } TD { BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; LINE-HEIGHT: 1; BORDER-TOP-WIDTH: 0px } TH { BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; LINE-HEIGHT: 1; BORDER-TOP-WIDTH: 0px } #editor { PADDING-BOTTOM: 16px; PADDING-TOP: 16px; PADDING-LEFT: 16px; PADDING-RIGHT: 16px; transition: margin-left .5s } H1 { FONT-SIZE: 24px; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } H2 { FONT-SIZE: 24px; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } H3 { FONT-SIZE: 24px; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } P { FONT-SIZE: 24px; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } A { FONT-SIZE: 24px; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } CODE { FONT-SIZE: 24px; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } H1 { FONT-SIZE: 26px; FONT-VARIANT: small-caps } TABLE { WIDTH: 95%; BORDER-COLLAPSE: collapse } TABLE { BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none } TD { BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none } TH { BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none } TR { VERTICAL-ALIGN: top; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } TD { VERTICAL-ALIGN: top; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } TD { } TH { } TABLE { PAGE-BREAK-INSIDE: auto } TR { PAGE-BREAK-INSIDE: avoid; PAGE-BREAK-AFTER: auto } THEAD { DISPLAY: table-header-group } TFOOT { DISPLAY: table-footer-group } </STYLE> <SCRIPT language=JScript type=text/jscript unselectable="on"> <!-- function preventDefault(e){ if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } } function toggleNav() { if (document.getElementById("mySidenav").style.width=="260px") { closeNav(); } else { openNav(); } } function openNav() { document.getElementById("mySidenav").style.width = "260px"; document.getElementById("editor").style.marginLeft = "260px"; document.getElementById("mySidenav").style.overflow = "scroll"; } function closeNav() { document.getElementById("mySidenav").style.width = "0"; document.getElementById("editor").style.marginLeft= "0"; document.getElementById("mySidenav").style.overflow = "hidden"; } function writeFile(){ // Deal with funny \ at work! var filename = window.location.pathname var fso, fileHandle; fso = new ActiveXObject("Scripting.FileSystemObject"); fileHandle = fso.CreateTextFile(filename.replace(/\//,""), true); fileHandle.write("<!DOCTYPE html>"); fileHandle.write("<HTML>"); fileHandle.write(document.documentElement.innerHTML); fileHandle.write("</HTML>"); fileHandle.close(); } function getSelected() { if (window.getSelection) { return window.getSelection(); } else if (document.getSelection) { return document.getSelection(); } else { var selection = document.selection && document.selection.createRange(); if (selection.text) { return selection.text; } return false; } } function insertText(text) { if (document.selection){ var range = document.selection.createRange(); range.pasteHTML(text); } } function followlink(){ alert('followlink called'); } function popupmenu(event) { alert('popupmenu called'); // Need to know the event.target - but don't want jquery! // use window.screenLeft window.screenTop } function Shortcuts(e){ if (!e) var e = window.event; var key = e.keyCode if (e.ctrlKey) { key = "ctrl"+key; } if (e.altKey) { key = "alt"+key; } if (e.shiftKey) { key = "shift"+key; } // alert(key) // ESC if ( key == 27) { writeFile(); window.close(); } // TAB alone if ( key == 9) { preventDefault(e); document.execCommand("indent", true, null); return false; } // Shift+TAB if (key == "shift9") { preventDefault(e); document.execCommand("outdent", true, null); return false; } // Ctrl+> if ( key == "ctrl190") { document.execCommand("indent", true); } // Ctrl+< if ( key == "ctrl188") { document.execCommand("outdent", true); } // Ctrl+Up TODO: Fails with this key if ( key == "ctrl38") { document.execCommand("superscript", true); } // Ctrl+Down TODO: Fails with this key if ( key == "ctrl40") { document.execCommand("subscript", true); } // Ctrl++ - Built in zoom+ // Ctrl+- - Built in zoom- // Ctrl+/ Try to wrap any selection if ( key == "ctrl191") { var sText = getSelected(); var code = "<code>" + sText + "</code>" insertText(code); } // Ctrl+\ Clear formatting if ( key == "ctrl220") { document.execCommand("removeFormat", true); } // Ctrl+A - Built in select all // Ctrl+B - Built in bold // Ctrl+C - Built in copy // Ctrl+D if ( key == "ctrl68") { document.execCommand("strikethrough", true); } // Ctrl+E - Editor if ( key == "ctrl69") { WshShell = new ActiveXObject("WScript.Shell"); WshShell.Run("O:/MyProfile/editor/micro.bat " + window.location.pathname,1,true) } // Ctrl+F - Built in Find // Ctrl+G - Google if ( key == "ctrl71") { WshShell = new ActiveXObject("WScript.Shell"); WshShell.run("http://www.google.com"); } // Ctrl+H - Hyperlink if ( key == "ctrl72") { var sText = getSelected(); var linkURL = prompt('Enter a URL:', 'http://'); // This is to match the automated format when URL is pasted/typed var link = '<A href="' + linkURL + '" target="_blank">' + sText + '</A>'; insertText(link); } // Ctrl+I - Built in italic // Ctrl+J - Jump to next H1 - for slide presentations if ( key == "ctrl74") { } // Ctrl+K - Built in hyperlink // Ctrl+L - Ordered list if ( key == "ctrl76") { document.execCommand("insertUnorderedList", true); } // Ctrl+M if ( key == "ctrl77") { // Undo default action of CRLF return false; } // Ctrl+N - Numbered List if ( key == "ctrl78") { document.execCommand("insertOrderedList", true); } // Ctrl+O - Empty // Ctrl+P - Built in Print // Ctrl+Q - Empty // Ctrl+R - Revert if ( key == "ctrl82") { window.location.reload(false); } // Ctrl+S - Save if ( key == "ctrl83") { writeFile(); } // Ctrl+T - Insert Table - TODO: need some css or in line styles if ( key == "ctrl84") { document.execCommand("indent", true, null); var table = "<table>" table = table +"<tr>" table = table +" <th>Company</th>" table = table +" <th>Contact</th>" table = table +" <th>Country</th>" table = table +"</tr>" table = table +"<tr>" table = table +" <td>Alfreds</td>" table = table +" <td>Maria</td>" table = table +" <td>Germany</td>" table = table +"</tr>" table = table +"<tr>" table = table +" <td>Centro</td>" table = table +" <td>Francisco</td>" table = table +" <td>Mexico</td>" table = table +"</tr>" table = table +"</table>" insertText(table); } // Ctrl+U - Built in Underline // Ctrl+V - Built in Paste // Ctrl+W - Write and Close if ( key == "ctrl87") { writeFile(); window.close(); } // Ctrl+X - Built in Cut // Ctrl+Y - Built in Redo // Ctrl+Z - Built in Undo // F1 if ( key == 112) { toggleNav(); } // Ctrl+0 if ( key == "ctrl48") { document.execCommand("formatBlock", false, "<P>"); } // Ctrl+1 if ( key == "ctrl49") { document.execCommand("formatBlock", false, "<H1>"); } // Ctrl+2 if ( key == "ctrl50") { document.execCommand("formatBlock", false, "<H2>"); } // Ctrl+3 if ( key == "ctrl51") { document.execCommand("formatBlock", false, "<H3>"); } } // Try to stop focus outside my div for (i=0; i<document.all.length; i++){ //ensure that all document elements except the content editable DIV are unselectable document.all(i).unselectable = "on"; } // Change title var filename = window.location.pathname document.title = " ContentEditor - " + filename.replace(/\//,"") // Focus on the editable section window.location.hash = '#editor'; // Settings document.execCommand("LiveResize", null, true); //--> </SCRIPT> </HEAD> <BODY tabIndex=-1> <DIV tabIndex=-1 id=mySidenav class=sidenav style="OVERFLOW: scroll; WIDTH: 260px" unselectable="on"><U><B>Help</B></U> <TABLE> <TBODY> <TR> <TD>ESC </TD> <TD>Save + exit</TD></TR> <TR> <TD>TAB </TD> <TD>Indent</TD></TR> <TR> <TD>Shift+TAB </TD> <TD>Outdent</TD></TR> <TR> <TD>Ctrl+A </TD> <TD>Select All</TD></TR> <TR> <TD>Ctrl+B </TD> <TD>Bold</TD></TR> <TR> <TD>Ctrl+C </TD> <TD>Copy</TD></TR> <TR> <TD>Ctrl+D </TD> <TD>Strikeout</TD></TR> <TR> <TD>Ctrl+E </TD> <TD>Edit page</TD></TR> <TR> <TD>Ctrl+F </TD> <TD>Find</TD></TR> <TR> <TD>Ctrl+I </TD> <TD>Italic</TD></TR> <TR> <TD>Ctrl+K </TD> <TD>Hyperlink</TD></TR> <TR> <TD>Ctrl+L </TD> <TD>Bullet list</TD></TR> <TR> <TD>Ctrl+N </TD> <TD>Num list</TD></TR> <TR> <TD>Ctrl+P </TD> <TD>Print</TD></TR> <TR> <TD>Ctrl+R </TD> <TD>Revert</TD></TR> <TR> <TD>Ctrl+S </TD> <TD>Save</TD></TR> <TR> <TD>Ctrl+T </TD> <TD>Insert table</TD></TR> <TR> <TD>Ctrl+U </TD> <TD>Underline</TD></TR> <TR> <TD>Ctrl+V </TD> <TD>Paste</TD></TR> <TR> <TD>Ctrl+W </TD> <TD>Save + exit</TD></TR> <TR> <TD>Ctrl+X </TD> <TD>Cut</TD></TR> <TR> <TD>Ctrl+Y </TD> <TD>Redo</TD></TR> <TR> <TD>Ctrl+Z </TD> <TD>Undo</TD></TR> <TR> <TD>Ctrl+/ </TD> <TD>Code</TD></TR> <TR> <TD>Ctrl+&lt; </TD> <TD>Superscript</TD></TR> <TR> <TD>Ctrl+&gt; </TD> <TD>Subscript</TD></TR> <TR> <TD>Ctrl+\\ </TD> <TD>Unformat</TD></TR> <TR> <TD>Ctrl+Del </TD> <TD>Del EOW</TD></TR> <TR> <TD>Ctrl+Bksp </TD> <TD>Del BOW</TD></TR> <TR> <TD>Ctrl+n </TD> <TD>Heading 1-3</TD></TR> <TR> <TD>F1 </TD> <TD>Toggle Help</TD></TR></TBODY></TABLE> <P></P></DIV> <DIV spellcheck=true tabIndex=-1 onkeyup=Shortcuts() id=editor contentEditable=true onkeydown="return (event.keyCode!=9);" style="MARGIN-LEFT: 260px" oncontextmenu=popupmenu()></DIV> <SCRIPT type=text/javascript> <!-- //--> </SCRIPT> </BODY></HTML> 嗨, 非常感谢迄今为止的所有建议,总而言之: 我的 writeFile() 功能总是会添加 <?XML:NAMESPACE PREFIX = "HTA" />,这使我处于 IE7 模式。 function writeFile(){ // Deal with funny \ at work! var filename = window.location.pathname var fso, fileHandle; fso = new ActiveXObject("Scripting.FileSystemObject"); fileHandle = fso.CreateTextFile(filename.replace(/\//,""), true); fileHandle.write("<!DOCTYPE html>"); fileHandle.write("<HTML>"); fileHandle.write(document.documentElement.innerHTML); fileHandle.write("</HTML>"); fileHandle.close(); } 我需要 <hta:application> 部分来控制窗口和图标。 <hta:application id=document.currentScript applicationname="MSI-BUILD" border="No" contextmenu="No" icon="O:\MyProfile\cmd\ContentEditor.ico" maximizebutton="yes" minimizebutton="yes" navigable="yes" scroll="yes" showintaskbar="yes" singleinstance="no" sysmenu="yes" version="2" > 使用函数查看documentMode和ScriptEngine,我得到带有JScript 11.0.16384的IE7。 ver = 'IE' + document.documentMode + ' , '; ver += ScriptEngine() + ' '; ver += ScriptEngineMajorVersion() + '.'; ver += ScriptEngineMinorVersion() + '.'; ver += ScriptEngineBuildVersion(); alert(ver); 所以,我认为我被 IE7 时代的脚本困住了。 亲切的问候加文霍尔特 您关于如何询问ChatGPT的建议非常有帮助,这个功能正是我所需要的: function scrollToNextH1() { var h1Elements = document.getElementsByTagName('h1'); var currentH1Index = -1; for (var i = 0; i < h1Elements.length; i++) { if (h1Elements[i].getBoundingClientRect().top > 0) { currentH1Index = i; break; } } if (currentH1Index !== -1 && currentH1Index < h1Elements.length - 1) { var nextH1 = h1Elements[currentH1Index + 1]; window.scrollTo(0, nextH1.offsetTop); } } 在这短短的时间内,我学到的东西比用搜索引擎搜索的日子还要多。乐于助人的人和优秀的法学硕士的结合是非常有效的。 非常感谢

回答 1 投票 0

在 HTML 应用程序 (.hta) 文件中编码 .ico

更新:我将页面上显示的图像更改为编码版本,而不是引用外部图像。我能够将图像放入 Base64 转换器,然后复制并粘贴...

回答 1 投票 0

将cmd数据显示到HTA和命令提示符窗口中

我遇到了一个问题,试图摆脱cmd弹出窗口并使命令中的所有数据出现在span标签中。我知道足以让命令正常工作,但不知道如何实现

回答 1 投票 0

获取HTA中某个目录的路径

我希望用户通过创建的输入标签提供文件夹或目录的路径,如下所示: var newinput = document.createElement('input'); newinput.type = "文件"; 新输入。

回答 1 投票 0

获取html中某个目录的路径

我希望用户通过创建的输入标签提供文件夹或目录的路径,如下所示: var newinput = document.createElement('input'); newinput.type = "文件"; 新输入。

回答 1 投票 0

修改GIF文件夹预览脚本

也许这里有人可以帮我修改这个脚本吗?我希望文件名位于 gif 下方,并且文本大小稍小一些,以便更多的 gif 可以出现在一行中。 <p>也许这里有人可以帮我修改这个脚本吗?我希望文件名位于 gif 下方,并且文本大小稍小一些,以便更多的 gif 可以出现在一行中。</p> <pre><code>&lt;script type=&#34;text/vbs&#34;&gt; set fso=CreateObject(&#34;Scripting.FileSystemObject&#34;) set fldr=fso.GetFolder(&#34;.&#34;) for each file in fldr.files if lcase(right(file.name,4))=&#34;.gif&#34; then document.write &#34;&lt;img src=&#34;&#34;&#34; &amp; file.name &amp; &#34;&#34;&#34;&gt;&#34; document.write file.name &amp; &#34;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&#34; end if next &lt;/script&gt; </code></pre> </question> <answer tick="false" vote="0"> <p>如评论中所述,您可以使用一些应用于 Div 的 CSS 并创建一个类来设置图像大小。大小可以指定为任何所需的单位。这里使用 Ems 是因为在设置不同缩放值的显示器上尺寸保持相当恒定。这是 HTA 代码:</p> <p><strong>GIFshow.hta</strong></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv=&#34;x-ua-compatible&#34; content=&#34;IE=10&#34;&gt; &lt;script language=&#34;VBScript&#34;&gt; Set oFSO = CreateObject(&#34;Scripting.FileSystemObject&#34;) Set oFolder = oFSO.GetFolder(&#34;.&#34;) For Each oFile In oFolder.Files If LCase(oFSO.GetExtensionName(oFile.Name)) = &#34;gif&#34; Then document.write &#34;&lt;div class=&#34;&#34;image-container&#34;&#34;&gt;&#34; document.write &#34;&lt;img class=&#34;&#34;image&#34;&#34; src=&#34;&#34;&#34; &amp; oFile.Name &amp; &#34;&#34;&#34; alt=&#34;&#34;&#34; &amp; oFile.Name &amp; &#34;&#34;&#34;&gt;&#34; document.write &#34;&lt;br&gt;&#34; &amp; oFile.Name document.write &#34;&lt;/div&gt;&#34; End If Next &lt;/script&gt; &lt;style&gt; .image-container { display: inline-block; text-align: center; } .image { width: 10em; height: 10em; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> </answer> </body></html>

回答 0 投票 0

如何浏览文件(Win7/64位)

我需要通过命令行应用程序快速编写一个简单的 GUI。需要两个步骤: 指定输入文件路径, 指定输出文件路径(不存在) 我发现了以前的帖子,h...

回答 3 投票 0

BAT/HTA 混合 - 如何转义 HTML 部分中的百分号?

我正在处理批处理/HTA 混合文件,并希望向应用程序添加一些背景音乐。当我尝试将 url(包含百分号)添加到 标签时,它不会播放任何内容...

回答 1 投票 0

HTA VBScript:在运行时从字符串或包含字符串的变量动态创建函数,如 Javascript 中使用 new Function() 构造函数

我正在尝试学习更多的 hta 和 VBScript,我想知道 VBS 是否允许像 Javascript 中那样创建动态函数: var f = new Function('函数名', 函数体); 或者 赢...

回答 0 投票 0

将 hta 窗口居中

如何将 HTA 窗口居中,使其位于屏幕中央,无论 HTA 大小的屏幕分辨率如何我有这个: Sub DoResize '不要使用 </desc> <question vote="8"> <p>如何将 HTA 窗口居中,使其位于屏幕中央,无论 HTA 大小的屏幕分辨率如何我有这个:</p> <pre><code>&lt;/head&gt; &lt;script&gt; Sub DoResize &#39;Do not use Window_Onload window.resizeTo 800,600 strComputer = &#34;.&#34; Set objWMIService = GetObject(&#34;Winmgmts:\\&#34; &amp; strComputer &amp; &#34;\root\cimv2&#34;) Set colItems = objWMIService.ExecQuery(&#34;Select * From Win32_DesktopMonitor&#34;) For Each objItem in colItems intHorizontal = objItem.ScreenWidth intVertical = objItem.ScreenHeight Next intLeft = (intHorizontal - 800) / 2 intTop = (intVertical - 600) / 2 window.moveTo intLeft, intTop End Sub DoResize() &#39;Run the subroutine to position the containing window (your HTA dialog) before the body is rendered. &lt;/script&gt; &lt;body&gt; </code></pre> <p>但是如果我更改屏幕分辨率,它就不起作用,并且会调整 HTA 窗口的大小。</p> <p>问题:无论屏幕分辨率的 HTA 大小如何,如何将 HTA 移动到屏幕中央。</p> </question> <answer tick="true" vote="6"> <p>为此使用 WMI 有点过分了。您可以使用 <pre><code>screen</code></pre> 对象代替:</p> <pre><code>window.resizeTo (800, 600); window.moveTo((screen.width - 800) / 2, (screen.height - 600) / 2); </code></pre> <p>如果您想在开始时调整窗口大小,请将上面的行放在 <pre><code>script</code></pre> 部分中的 (JS) <pre><code>head</code></pre> 标记中,甚至在 <pre><code>&lt;hta: application&gt;</code></pre> 标记之前,或者在事件处理程序中或任何位置使用代码需要它。</p> <p>如果您想将任务栏的高度排除在居中区域之外,可以使用 <pre><code>screen.availHeight</code></pre> 代替 <pre><code>screen.height</code></pre>。</p> </answer> <answer tick="false" vote="2"> <pre><code>var winWidth = 800, winHeight = 600; window.resizeTo(winWidth, winHeight); window.moveTo((screen.width - winWidth) / 2, (screen.height - winHeight) / 2); </code></pre> </answer> <answer tick="false" vote="0"> <p>HTA窗口</p> <blockquote> <p>`</p> </blockquote> <p></p><div data-babel="false" data-lang="js" data-hide="false" data-console="true"> <div> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;File Operations&lt;/title&gt; &lt;hta:application id=&#34;FileOperationsHTA&#34; applicationname=&#34;FileOperationsHTA&#34; singleinstance=&#34;yes&#34; maximizebutton=&#34;no&#34; minimizebutton=&#34;no&#34; windowstate=&#34;normal&#34; scroll=&#34;no&#34; navigable=&#34;yes&#34; showintaskbar=&#34;no&#34; contextmenu=&#34;no&#34; selection=&#34;no&#34; /&gt; &lt;/head&gt; &lt;body onload=&#34;showFields()&#34;&gt; &lt;h1&gt;File Operations&lt;/h1&gt; &lt;label for=&#34;operationCombo&#34;&gt;Select operation:&lt;/label&gt; &lt;select id=&#34;operationCombo&#34; onchange=&#34;showFields()&#34;&gt; &lt;option value=&#34;&#34;&gt;Select an operation&lt;/option&gt; &lt;option value=&#34;move&#34;&gt;Move&lt;/option&gt; &lt;option value=&#34;copy&#34;&gt;Copy&lt;/option&gt; &lt;option value=&#34;delete&#34;&gt;Delete&lt;/option&gt; &lt;option value=&#34;newfolder&#34;&gt;New Folder&lt;/option&gt; &lt;option value=&#34;rename&#34;&gt;Rename&lt;/option&gt; &lt;/select&gt; &lt;div id=&#34;sourceField&#34; style=&#34;display: none;&#34;&gt; &lt;label for=&#34;sourcePath&#34;&gt;Source path:&lt;/label&gt; &lt;input type=&#34;text&#34; id=&#34;sourcePath&#34; /&gt; &lt;/div&gt; &lt;div id=&#34;destinationField&#34; style=&#34;display: none;&#34;&gt; &lt;label for=&#34;destinationPath&#34;&gt;Destination path:&lt;/label&gt; &lt;input type=&#34;text&#34; id=&#34;destinationPath&#34; /&gt; &lt;/div&gt; &lt;div id=&#34;deleteField&#34; style=&#34;display: none;&#34;&gt; &lt;label for=&#34;deletePath&#34;&gt;File/Folder to delete:&lt;/label&gt; &lt;input type=&#34;text&#34; id=&#34;deletePath&#34; /&gt; &lt;/div&gt; &lt;div id=&#34;newFolderField&#34; style=&#34;display: none;&#34;&gt; &lt;label for=&#34;parentPath&#34;&gt;Parent path for new folder:&lt;/label&gt; &lt;input type=&#34;text&#34; id=&#34;parentPath&#34; /&gt; &lt;label for=&#34;newFolderName&#34;&gt;New folder name:&lt;/label&gt; &lt;input type=&#34;text&#34; id=&#34;newFolderName&#34; /&gt; &lt;/div&gt; &lt;div id=&#34;renameField&#34; style=&#34;display: none;&#34;&gt; &lt;label for=&#34;sourcePathRename&#34;&gt;Source path:&lt;/label&gt; &lt;input type=&#34;text&#34; id=&#34;sourcePathRename&#34; /&gt; &lt;label for=&#34;destinationPathRename&#34;&gt;Destination path:&lt;/label&gt; &lt;input type=&#34;text&#34; id=&#34;destinationPathRename&#34; /&gt; &lt;label for=&#34;newFileName&#34;&gt;New filename:&lt;/label&gt; &lt;input type=&#34;text&#34; id=&#34;newFileName&#34; /&gt; &lt;/div&gt; &lt;button id=&#34;executeButton&#34; onclick=&#34;executeOperation()&#34;&gt;Execute&lt;/button&gt; &lt;script type=&#34;text/javascript&#34;&gt; function showFields() { var operation = document.getElementById(&#39;operationCombo&#39;).value; var sourceField = document.getElementById(&#39;sourceField&#39;); var destinationField = document.getElementById(&#39;destinationField&#39;); var deleteField = document.getElementById(&#39;deleteField&#39;); var newFolderField = document.getElementById(&#39;newFolderField&#39;); var renameField = document.getElementById(&#39;renameField&#39;); var executeButton = document.getElementById(&#39;executeButton&#39;); sourceField.style.display = &#39;none&#39;; destinationField.style.display = &#39;none&#39;; deleteField.style.display = &#39;none&#39;; newFolderField.style.display = &#39;none&#39;; renameField.style.display = &#39;none&#39;; switch (operation) { case &#39;move&#39;: sourceField.style.display = &#39;block&#39;; destinationField.style.display = &#39;block&#39;; break; case &#39;copy&#39;: sourceField.style.display = &#39;block&#39;; destinationField.style.display = &#39;block&#39;; break; case &#39;delete&#39;: deleteField.style.display = &#39;block&#39;; break; case &#39;newfolder&#39;: newFolderField.style.display = &#39;block&#39;; break; case &#39;rename&#39;: renameField.style.display = &#39;block&#39;; document.getElementById(&#39;sourcePathRename&#39;).disabled = false; document.getElementById(&#39;destinationPathRename&#39;).disabled = false; document.getElementById(&#39;newFileName&#39;).disabled = false; break; } } function executeOperation() { var operation = document.getElementById(&#39;operationCombo&#39;).value; switch (operation) { case &#39;move&#39;: var sourcePath = document.getElementById(&#39;sourcePath&#39;).value; var destinationPath = document.getElementById(&#39;destinationPath&#39;).value; moveFilesWithWildcard(sourcePath, destinationPath); break; case &#39;copy&#39;: var sourcePath = document.getElementById(&#39;sourcePath&#39;).value; var destinationPath = document.getElementById(&#39;destinationPath&#39;).value; copyFilesWithWildcard(sourcePath, destinationPath); break; case &#39;delete&#39;: var deletePath = document.getElementById(&#39;deletePath&#39;).value; deleteFilesWithWildcard(deletePath); break; case &#39;newfolder&#39;: var parentPath = document.getElementById(&#39;parentPath&#39;).value; var newFolderName = document.getElementById(&#39;newFolderName&#39;).value; createNewFolder(parentPath, newFolderName); break; case &#39;rename&#39;: var sourcePathRename = document.getElementById(&#39;sourcePathRename&#39;).value; var destinationPathRename = document.getElementById(&#39;destinationPathRename&#39;).value; var newFileName = document.getElementById(&#39;newFileName&#39;).value; renameFile(sourcePathRename, destinationPathRename, newFileName); break; } } function renameFile(sourcePath, destinationPath, newFileName) { var fso = new ActiveXObject(&#34;Scripting.FileSystemObject&#34;); if (fso.FileExists(sourcePath)) { try { fso.MoveFile(sourcePath, fso.BuildPath(destinationPath, newFileName)); alert(&#39;Rename operation executed.\nSource: &#39; + sourcePath + &#39;\nDestination: &#39; + destinationPath); } catch (e) { alert(&#39;Error renaming file: &#39; + e.message); } } else { alert(&#39;Source file not found.&#39;); } } function moveFilesWithWildcard(sourcePath, destinationPath) { var fso = new ActiveXObject(&#34;Scripting.FileSystemObject&#34;); var parentFolder = fso.GetParentFolderName(sourcePath); var wildcard = fso.GetFileName(sourcePath); var parentFolderObj = fso.GetFolder(parentFolder); if (fso.FolderExists(parentFolder)) { try { var files = new Enumerator(parentFolderObj.Files); var subFolders = new Enumerator(parentFolderObj.SubFolders); var regex = new RegExp(wildcard.replace(/\./g, &#34;\\.&#34;).replace(/\*/g, &#34;.*&#34;), &#34;i&#34;); for (; !files.atEnd(); files.moveNext()) { var file = files.item(); if (regex.test(file.Name)) { var sourceFile = fso.BuildPath(parentFolder, file.Name); var destinationFile = fso.BuildPath(destinationPath, file.Name); fso.MoveFile(sourceFile, destinationFile); } } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); if (regex.test(subFolder.Name)) { var newDestPath = fso.BuildPath(destinationPath, subFolder.Name); fso.CreateFolder(newDestPath); moveFilesRecursive(subFolder, newDestPath); } } } catch (e) { alert(&#39;Error moving files/folders with wildcard.&#39;); } } else { alert(&#39;Parent path not found.&#39;); } } function moveFilesRecursive(folder, destinationPath) { var fso = new ActiveXObject(&#34;Scripting.FileSystemObject&#34;); var files = new Enumerator(folder.Files); var subFolders = new Enumerator(folder.SubFolders); for (; !files.atEnd(); files.moveNext()) { var file = files.item(); var destinationFile = fso.BuildPath(destinationPath, file.Name); fso.MoveFile(file.Path, destinationFile); } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); var newDestPath = fso.BuildPath(destinationPath, subFolder.Name); fso.CreateFolder(newDestPath); moveFilesRecursive(subFolder, newDestPath); } } function copyFiles(sourcePath, destinationPath) { var fso = new ActiveXObject(&#34;Scripting.FileSystemObject&#34;); var folder = fso.GetFolder(sourcePath); if (fso.FolderExists(destinationPath)) { try { copyFilesRecursive(folder, destinationPath); alert(&#39;Copy operation executed.\nSource Path: &#39; + sourcePath + &#39;\nDestination Path: &#39; + destinationPath); } catch (e) { alert(&#39;Error copying files/folders.&#39;); } } else { alert(&#39;Destination path not found.&#39;); } } function copyFilesRecursive(folder, destinationPath) { var fso = new ActiveXObject(&#34;Scripting.FileSystemObject&#34;); var files = new Enumerator(folder.Files); var subFolders = new Enumerator(folder.SubFolders); for (; !files.atEnd(); files.moveNext()) { var file = files.item(); fso.CopyFile(file.Path, fso.BuildPath(destinationPath, file.Name), true); } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); var newDestPath = fso.BuildPath(destinationPath, subFolder.Name); fso.CreateFolder(newDestPath); copyFilesRecursive(subFolder, newDestPath); } } function moveFilesWithWildcard(sourcePath, destinationPath) { var fso = new ActiveXObject(&#34;Scripting.FileSystemObject&#34;); var parentFolder = fso.GetParentFolderName(sourcePath); var wildcard = fso.GetFileName(sourcePath); var parentFolderObj = fso.GetFolder(parentFolder); if (fso.FolderExists(parentFolder)) { try { var files = new Enumerator(parentFolderObj.Files); var subFolders = new Enumerator(parentFolderObj.SubFolders); var regex = new RegExp(wildcard.replace(/\./g, &#34;\\.&#34;).replace(/\*/g, &#34;.*&#34;), &#34;i&#34;); for (; !files.atEnd(); files.moveNext()) { var file = files.item(); if (regex.test(file.Name)) { var sourceFile = fso.BuildPath(parentFolder, file.Name); var destinationFile = fso.BuildPath(destinationPath, file.Name); fso.MoveFile(sourceFile, destinationFile); } } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); if (regex.test(subFolder.Name)) { var newDestPath = fso.BuildPath(destinationPath, subFolder.Name); fso.CreateFolder(newDestPath); moveFilesRecursive(subFolder, newDestPath); } } } catch (e) { alert(&#39;Error moving files/folders with wildcard.&#39;); } } else { alert(&#39;Parent path not found.&#39;); } } function moveFilesRecursive(folder, destinationPath) { var fso = new ActiveXObject(&#34;Scripting.FileSystemObject&#34;); var files = new Enumerator(folder.Files); var subFolders = new Enumerator(folder.SubFolders); for (; !files.atEnd(); files.moveNext()) { var file = files.item(); var destinationFile = fso.BuildPath(destinationPath, file.Name); fso.MoveFile(file.Path, destinationFile); } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); var newDestPath = fso.BuildPath(destinationPath, subFolder.Name); fso.CreateFolder(newDestPath); moveFilesRecursive(subFolder, newDestPath); } } function copyFilesWithWildcard(sourcePath, destinationPath) { var fso = new ActiveXObject(&#34;Scripting.FileSystemObject&#34;); if (fso.FileExists(sourcePath)) { // Source path is a single file var sourceFolder = fso.GetParentFolderName(sourcePath); var sourceFileName = fso.GetFileName(sourcePath); if (fso.FileExists(destinationPath)) { // Destination path includes a filename, create a new folder in the destination path var destinationParentFolder = fso.GetParentFolderName(destinationPath); var newFolderName = fso.GetBaseName(destinationPath); destinationPath = fso.BuildPath(destinationParentFolder, newFolderName); } else if (!fso.FolderExists(destinationPath)) { // Destination folder does not exist, create it fso.CreateFolder(destinationPath); } // Perform the copy operation fso.CopyFile(sourcePath, fso.BuildPath(destinationPath, sourceFileName)); alert(&#39;Copy operation executed.\nSource: &#39; + sourcePath + &#39;\nDestination: &#39; + destinationPath); } else if (fso.FolderExists(sourcePath)) { // Source path is a folder var parentFolder = fso.GetParentFolderName(sourcePath); var wildcard = fso.GetFileName(sourcePath); var parentFolderObj = fso.GetFolder(parentFolder); if (fso.FolderExists(parentFolder)) { try { var files = new Enumerator(parentFolderObj.Files); var subFolders = new Enumerator(parentFolderObj.SubFolders); var regex = new RegExp(wildcard.replace(/\./g, &#34;\\.&#34;).replace(/\*/g, &#34;.*&#34;), &#34;i&#34;); // Collect files and folders matching the wildcard var filesToCopy = []; var foldersToCopy = []; for (; !files.atEnd(); files.moveNext()) { var file = files.item(); if (regex.test(file.Name)) { filesToCopy.push(file); } } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); if (regex.test(subFolder.Name)) { foldersToCopy.push(subFolder); } } // Perform the copy operation if (!fso.FolderExists(destinationPath)) { // Destination folder does not exist, create it fso.CreateFolder(destinationPath); } for (var i = 0; i &lt; filesToCopy.length; i++) { var file = filesToCopy[i]; file.Copy(fso.BuildPath(destinationPath, file.Name)); } for (var i = 0; i &lt; foldersToCopy.length; i++) { var folder = foldersToCopy[i]; copyFolderRecursive(folder, fso.BuildPath(destinationPath, folder.Name)); } alert(&#39;Copy operation executed.\nSource: &#39; + sourcePath + &#39;\nDestination: &#39; + destinationPath); } catch (e) { alert(&#39;Error copying files/folders with wildcard: &#39; + e.message); } } else { alert(&#39;Source parent path not found.&#39;); } } else { alert(&#39;Source path not found.&#39;); } } function copyFolderRecursive(sourceFolder, destinationFolder) { var fso = new ActiveXObject(&#34;Scripting.FileSystemObject&#34;); fso.CreateFolder(destinationFolder); var files = new Enumerator(sourceFolder.Files); var subFolders = new Enumerator(sourceFolder.SubFolders); for (; !files.atEnd(); files.moveNext()) { var file = files.item(); file.Copy(fso.BuildPath(destinationFolder, file.Name)); } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); copyFolderRecursive(subFolder, fso.BuildPath(destinationFolder, subFolder.Name)); } } function createNewFolder(parentPath, newFolderName) { var fso = new ActiveXObject(&#34;Scripting.FileSystemObject&#34;); var fullPath = fso.BuildPath(parentPath, newFolderName); try { fso.CreateFolder(fullPath); alert(&#39;New folder created successfully.\nPath: &#39; + fullPath); } catch (e) { alert(&#39;Error creating new folder: &#39; + e.message); } } function deleteFilesWithWildcard(deletePath) { var fso = new ActiveXObject(&#34;Scripting.FileSystemObject&#34;); var parentFolder = fso.GetParentFolderName(deletePath); var wildcard = fso.GetFileName(deletePath); var parentFolderObj = fso.GetFolder(parentFolder); if (fso.FolderExists(parentFolder)) { try { var files = new Enumerator(parentFolderObj.Files); var subFolders = new Enumerator(parentFolderObj.SubFolders); var regex = new RegExp(wildcard.replace(/\./g, &#34;\\.&#34;).replace(/\*/g, &#34;.*&#34;), &#34;i&#34;); // Collect files and folders matching the wildcard var filesToDelete = []; var foldersToDelete = []; for (; !files.atEnd(); files.moveNext()) { var file = files.item(); if (regex.test(file.Name)) { filesToDelete.push(file); } } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); if (regex.test(subFolder.Name)) { foldersToDelete.push(subFolder); } } // Delete files for (var i = 0; i &lt; filesToDelete.length; i++) { filesToDelete[i].Delete(); } // Delete folders for (var i = 0; i &lt; foldersToDelete.length; i++) { deleteFolderRecursive(foldersToDelete[i]); } alert(&#39;Delete operation executed.\nPath: &#39; + deletePath); } catch (e) { alert(&#39;Error deleting files/folders with wildcard: &#39; + e.message); } } else { alert(&#39;Parent path not found.&#39;); } } function deleteFolderRecursive(folder) { var fso = new ActiveXObject(&#34;Scripting.FileSystemObject&#34;); var subFolders = new Enumerator(folder.SubFolders); for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); deleteFolderRecursive(subFolder); } fso.DeleteFolder(folder.Path); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt;</code></pre> </div> </div> <p></p> <p>`</p> </answer> <answer tick="false" vote="0"> <p>函数 logMessage(消息) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var logFile = fso.OpenTextFile("file_operations.log", 8, true); // 8 用于追加</p> <pre><code> var now = new Date(); var timestamp = now.toLocaleString(); logFile.WriteLine(&#34;[&#34; + timestamp + &#34;] &#34; + message); logFile.Close(); } </code></pre> </answer> </body></html>

回答 0 投票 0

VBScript 变量为空

我正在尝试在 VBScript 变量中捕获机器的 DNS 服务器地址。这将在 .hta 文件中使用。 到目前为止,我的代码如下。它返回如下所示的错误。我...

回答 0 投票 0

清除一个<input type=file>

我正在写一个HTA,希望用户能够很容易地能够使用浏览器选择一个.txt文件。这个.txt文件将被逐行读取并读入一个数组。所以,我在使用

回答 3 投票 0

使用HTA应用程序播放直播

我有一个直播,我想在我的HTA应用程序上播放。我已经尝试使用这个答案。 主要的

回答 1 投票 2

HTA-完全透明的主体

[我想知道,是否有办法完全删除任何类型的HTA背景(就像绝对删除背景一样,因此该应用后面的窗口实际上是可见的]]

hta
回答 1 投票 0

如何在当前文件夹中的hta中使用PowerShell在子文件夹中执行.bat文件?

我正在尝试执行位于hta文件所在当前文件夹子文件夹中的.bat文件。我在这里找到了文件夹结构>>文件夹结构下面是我的.hta代码的示例&...

回答 1 投票 0

hta / javascript如何执行具有相对路径的应用程序

我正在建立一个.hta(使用javascript),我想从中启动几个应用程序。但是,当我执行.hta时,我收到错误消息,找不到文件,这是代码:] >>

回答 1 投票 2

限制/拒绝用户使用javascript在HTA中输入10个字符

我想创建一个Java脚本来设置html文本框中的输入,该输入必须是10个字母数字输入。 [ ]

回答 1 投票 0

在IE 11中禁止Active X警告“此页面上的Active X控件”

我有一个已在IE中运行的Oracle表单应用程序,目前我们在11上运行。它通过URL调用外部Web应用程序,该URL需要在Chrome中运行。因为在IE中启动URL会导致...

回答 1 投票 0

HTA iframe始终会打开一个新窗口

我正在尝试在Windows 10计算机上运行的HTA应用程序中使用iframe。父页面和嵌入式页面都是HTA应用程序。但是,iframe页面/应用程序始终会在新的页面中打开...

回答 1 投票 0

在HTA应用程序中使用XDomainRequest对象

我有一个HTA应用程序,该应用程序通过ajax调用获取一些数据。我想为此使用XMLHttpRequest。这种方法给了我想要的结果,但是在...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.