<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>
<frameset rows="60px, *">
<frame src="topo.htm" name="topo" id="topo" application="yes" />
<frame src="http://localhost/nph-psf.exe?HOSTID=AD&ALIAS=" name="conteudo" id="psyncLink" application="yes" />
</frameset>
</html>
In my frameset, I have a webpage loading. I can't edit the code that is displayed from
http://localhost/nph-psf.exe?HOSTID=AD&ALIAS=
The page has a button that needs to be clicked in order to proceed. I want to automate that with my HTA application so the button is automatically clicked for the user upon page load.
The code can be in VBScript or JavaScript. The key is to have the button be clicked PROGRAMATICALLY so the user doesn't have to.
The button that I want to click on has the following line of HTML code
<INPUT border=0 type=image alt="Use a password" name="SUBMIT-password.pss" src="docs/pics/en-us/useapassword_button.jpg">
One way;
<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>
<frameset rows="60px, *">
<frame src="topo.htm" name="topo" id="topo" application="yes" />
<frame src="http://localhost/nph-psf.exe?HOSTID=AD&ALIAS=" name="conteudo" id="psyncLink" application="yes" onload="doClick(this);"/>
</frameset>
</html>
You can try this javascript. Since the element doesn't have an ID we have to grab it by Name which returns an array. You can also get by tagname but I wasn't sure how many inputs there would be on the other page.
try{
window.frames[1].document.getElementsByName('SUBMIT-password.pss')[0].click();
}catch(Exception){
alert('hi');
}
If you have access to the page that you are loading you can simulate a click on the button. The easiest way to do this I think is jQuery click. Check this: http://api.jquery.com/click/.
Add a small script at the end of the page that clicks it and should be ok.
If you don't have access... You can still manipulate the dom to select the button and click it if the page is loaded in an iframe but would be a bit harder.
来源:https://stackoverflow.com/questions/10997163/how-to-programatically-click-a-button-thats-loaded-from-another-page