简体   繁体   English

如何使用VB.NET执行网页上的javascript函数?

[英]How can I execute a javascript function that is on a web page using VB.NET?

What I am trying to do is go to a website using a webbrowser, and then simulate a click. 我想做的是使用网络浏览器转到一个网站,然后模拟一次点击。 I can do this easy enough when the click is on a regular button, not handling javascript. 当单击常规按钮时,我可以很容易地做到这一点,而不用处理javascript。 But it seems that the website has a javascript function handling the click that I want to simulate: 但似乎该网站具有处理我要模拟的点击的javascript函数:

<script language='JavaScript' type='text/javascript'><!-- function setgotopageNR() { if (document.gotopageform.gotopage_reverse.value=='1') { document.gotopageform.page.value=8+1-document.gotopageform.gotopage.value; } else { document.gotopageform.page.value=document.gotopageform.gotopage.value; } } //--></script>

I have tried various solutions found through googling, such as WebBrowser1.Document.InvokeScript, also opening the website in internet explorer and then converting its document to IHTMLDocument2 and getting its parent window as IHTMLWindow2 and then using execScript. 我尝试了通过谷歌搜索找到的各种解决方案,例如WebBrowser1.Document.InvokeScript,还在Internet Explorer中打开网站,然后将其文档转换为IHTMLDocument2,并将其父窗口获取为IHTMLWindow2,然后使用execScript。

Any ideas? 有任何想法吗?

Normally one would do document.getElementById(id).click() . 通常情况下,会执行document.getElementById(id).click() It should be easy to convert to whatever language you are using to host web browser. 转换为用于托管Web浏览器的任何语言都应该很容易。

If click does not work please post more details on solutions you've already tried and what problems you got. 如果click不起作用,请在您已经尝试过的解决方案以及遇到的问题上发布更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM