简体   繁体   English

如何在不可见时强制加载Twebbrowser控件中的页面

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

i need to execute some javascript functions from delphi code, but this functions fails if the page is not loaded in the Twebbrowser control. 我需要从delphi代码执行一些javascript函数,但如果页面未在Twebbrowser控件中加载,则此函数将失败。 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. 所以问题是如果页面位于一个未激活的tabhet中,则在标签页变为活动状态之前不会加载页面。

the question is How to force load a page in a Twebbrowser control when this is not visible. 问题是当不可见时,如何在Twebbrowser控件中强制加载页面。

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 测试这个行为只是在第二个标签页中放置一个pagecontrol,带有2个tabheet和一个twebbrowser,现在在表单的oncreate事件中放入此代码

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. 提前致谢。

Call WebBrowser1.HandleNeeded; 调用WebBrowser1.HandleNeeded; before you call WebBrowser1.Navigate 在调用WebBrowser1.Navigate之前

I cannot reproduce the behavior you document. 我无法重现您记录的行为。 I have followed your instructions one page control, two tabs, webbrowser on second (invisible) tab. 我已按照您的说明在第二个(不可见)选项卡上显示一个页面控件,两个选项卡,webbrowser。

To know if the page is loading, I have capture some events of the webbrowser. 要知道页面是否正在加载,我已经捕获了一些webbrowser的事件。 I see that onBeforeNavigate , onTitleChange and OnNavigateComplete all get fired without having to make second tabsheet visible. 我看到onBeforeNavigateonTitleChangeOnNavigateComplete都被触发,而不必使第二个标签页可见。

Setting your javascript code to execute under one of those events may solve your problem. 将您的javascript代码设置为在其中一个事件下执行可能会解决您的问题。

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

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