How to force load a page in Twebbrowser control when this is not visible

放肆的年华 提交于 2021-02-18 11:31:10

问题


i need to execute some javascript functions from delphi code, but this functions fails if the page is not loaded in the Twebbrowser control. so the problem is if page is located in a tabshet wich is not active the page is not loaded until the tabsheet is become active.

the question is How to force load a page in a Twebbrowser control when this is not visible.

to test this behaviour just put a pagecontrol, with 2 tabsheets , and a twebbrowser in the second tabsheet, now in the oncreate event of the form put this code

WebBrowser1.Navigate('http://stackoverflow.com');

now when you run the app the page only loads when you makes the second tabsheet visible.

thanks in advance.


回答1:


Call WebBrowser1.HandleNeeded; before you call WebBrowser1.Navigate




回答2:


I cannot reproduce the behavior you document. I have followed your instructions one page control, two tabs, webbrowser on second (invisible) tab.

To know if the page is loading, I have capture some events of the webbrowser. I see that onBeforeNavigate, onTitleChange and OnNavigateComplete all get fired without having to make second tabsheet visible.

Setting your javascript code to execute under one of those events may solve your problem.



来源:https://stackoverflow.com/questions/4179377/how-to-force-load-a-page-in-twebbrowser-control-when-this-is-not-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!