如何在HTA文件中使用VBScript单击按钮

时间:2012-06-07 18:10:25

标签: html vba vbscript html-form hta

我的代码看起来像

<html>
<head>
<title>My HTML application</title>
<HTA:APPLICATION 
    id="frames" 
    border="thin" 
    caption="yes" 
    icon="http://www.google.com/favicon.ico" 
    showintaskbar="yes" 
    singleinstance="yes" 
    sysmenu="yes" 
    navigable="yes" 
    contextmenu="no" 
    innerborder="no" 
    scroll="auto" 
    scrollflat="yes" 
    selection="yes" 
    windowstate="normal" />
</head>

<script language="VBScript">

Sub Window_OnLoad
  'This method will be called when the application loads
  'Add your code here
  GetUserName
End Sub

Sub GetUserName() 
    Set objNetwork = CreateObject("WScript.Network")
    linkTo("http://servername/nph-psf.exe?HOSTID=AD&ALIAS=" & objNetwork.UserName)
    Set objNetwork = Nothing 
End Sub

Sub linkTo(strLink) 
    Document.getElementById("psyncLink").src = strLink
End Sub

Sub checkInputPage
    Document.theforms.name
End Sub

</script>        
    </head> 
    <frameset rows="60px, *"> 
        <frame src="topo.htm" name="topo" id="topo" application="yes" /> 
        <frame src="http://servername/nph-psf.exe?HOSTID=AD&ALIAS=" name="conteudo" id="psyncLink" application="yes" /> 
    </frameset> 
</html> 

并且页面加载了2个按钮,如何以编程方式执行单击操作?

<INPUT border=0 type=image alt="Use a password" name="SUBMIT-password.pss" src="docs/pics/en-us/useapassword_button.jpg">

请注意,我无法更改从中加载的任何代码 因为我没有写那个目录的priv。我正在创建一个HTA脚本,可以编程方式点击该页面上的按钮和链接,以帮助我们的用户更改密码

2 个答案:

答案 0 :(得分:4)

请参阅How to click a button using VBScript in an HTA file

这正是我所需要的

<script type="text/javascript"> 
function doClick(fr) { 
    var btn = fr.contentWindow.document.getElementsByName("SUBMIT-password.pss"); 
    if (btn.length == 0) { 
        alert("no button!"); 
        return; 
    } else { 
        btn[0].click(); 
    } 
} 
</script>

答案 1 :(得分:2)

仅举例

<INPUT border=0 type=image alt="Use a password" name="cmdBtn" src="docs/pics/en-us/useapassword_button.jpg" onclick="cmdBtn_Click">

VB SCRIPT

<script language="vbscript">
   sub cmdBtn_Click()
       msgbox("Clicked !") 
   end sub
</script>

<INPUT type="Button" value="Click Me" name="cmdBtn" />

<强> VBSCRIPT

<SCRIPT LANGUAGE="VBSCRIPT" EVENT="OnClick" FOR="cmdBtn">
    msgbox("Clicked !")
</script>

如果您点击该按钮,则会显示带有“Clicked!”文字的提醒在它。