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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10937398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 16:25:10  来源:igfitidea点击:

How to click a button using VBScript in an HTA file

htmlvbavbscriptformshta

提问by Cocoa Dev

My code looks like

我的代码看起来像

<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> 

and the page loads with 2 buttons, how do I perform the click operation programatically?

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

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

Please note that I can not change any code thats loaded from because I do not have write privs to that directory. I am creating an HTA script that can programatically click buttons and links on that page to assist our users with changing their password

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

回答by Cocoa Dev

See How to click a button using VBScript in an HTA file

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

This does exactly what I needed

这正是我需要的

<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>

回答by The Alpha

Only an example

只是一个例子

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

VB SCRIPT

VB脚本

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

OR

或者

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

VBSCRIPT

脚本

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

If you click the button then it will show an alert with text 'Clicked !' in it.

如果您单击该按钮,它将显示带有文本“已单击!”的警报。在里面。