【问题标题】:HTA opens internet explorer on enterbuttonHTA 在 Enter 按钮上打开 Internet Explorer
【发布时间】:2014-03-14 22:31:21
【问题描述】:

我正在尝试学习 HTA 的基础知识,但遇到了问题。

我想要一个带有文本框的 HTA GUI,我可以将自己的 VBScript 添加到其中。 当我在文本框中按 Enter 时,Internet Explorer 会打开并提示我打开/保存 HTA 文件。

是什么导致了这种情况发生,我该如何阻止它?我使用的是 Windows 8 并拥有 IE10。

<html>
<head>
<HTA:APPLICATION
  APPLICATIONNAME="Simple HTA"
SINGLEINSTANCE = "Yes"
  SYSMENU="yes">
<title>Simple HTA</title>
<style type="text/css">
  body {background-color:lightsteelblue;}
  p {font:bold 18px arial;}
</style>

<script language="VBScript">
sub checkEnter
  With document.parentWindow.event
    if .keycode = 13 then
      Validate()
    End if
  End With
End sub
sub validate()
x=msgbox("success")
End sub
</script>

</head>
<body>
<form>
<input type="text" onkeydown=checkEnter size=60 id="request" value="" />
<input type="button" name="btnStart" value="Start" onClick="Validate()" />
</form>
</body>
</html>

【问题讨论】:

    标签: internet-explorer vbscript hta


    【解决方案1】:

    发生这种情况是因为“HTA 中的一个小 IE”在文本输入上按 ENTER 时会提交表单。有几种方法可以解决这个问题:

    如果您不需要 form,只需将其删除,或将其替换为 div

    使用函数checkEnter 并设置:

    event.cancelBubble = true
    event.returnValue = false
    return false
    

    【讨论】:

      【解决方案2】:

      我不知道这个例子是否对你有帮助,但试试看吧:)

      <html>
      <head>
      <HTA:APPLICATION
      APPLICATIONNAME="Search on Google with Internet Explorer"
      BORDER="THIN"
      BORDERSTYLE="NORMAL"
      ICON="magnify.exe"
      INNERBORDER="NO"
      MAXIMIZEBUTTON="NO"
      MINIMIZEBUTTON="NO"
      SCROLL="NO"
      SELECTION="NO"
      SYSMENU="YES"
      SINGLEINSTANCE="YES"/>
      <META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES">
      <script language="VBScript">
      Option Explicit
      Dim Titre
      Titre = "Search on Google with Internet Explorer"
      Self.document.title = Titre
      Sub window_onload()
          CALL CenterWindow(300,180)
          Self.document.bgColor = "Orange"
      End Sub
      Sub RunProgram()
          Dim X,Y,URL,objShell,Param,MaCmd
          X = text1.value
          Y = text2.value
          Param = "#q="& X & "+" & Y &""
          URL = "www.google.com"& Param
          Set objShell = CreateObject("Wscript.Shell")
          msgbox("iexplore.exe " & DblQuote(URL)),VbInformation,Titre
          MaCmd = "iexplore.exe "& DblQuote(URL) &""
          objShell.Run(MaCmd)
      End Sub
      '***************************************************
      Function DblQuote(Str)
          DblQuote = Chr(34) & Str & Chr(34)
      End Function
      '***************************************************
      'Position Windows
      Sub CenterWindow(x,y)
          Dim iLeft,itop
          window.resizeTo x,y
          iLeft = window.screen.availWidth/2 - x/2
          itop = window.screen.availHeight/2 - y/2
          window.moveTo ileft, itop
      End Sub
      </script>
      </head>
      <body><center>
      Text1 : <input type="text" id="text1" Name="text1" value="Hackoo"><br>
      Text2 : <input type="text" id="text2" Name="text2" value="Vbscript+HTA"><br><br>
      <input type="submit" Value="Search on Google" onclick="RunProgram()"></center>
      </body>
      </html>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-26
        • 1970-01-01
        • 2012-01-28
        • 2010-10-04
        • 1970-01-01
        • 2020-02-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多