webbrowser does not display page until an event occurs

点点圈 提交于 2019-12-13 04:34:33

问题


I am using the .net compact framework webbrowser control on a Windows CE device. The .Net application has a web server running on the device under a different thread. The webbrowser interacts with the web server as per normal browser functionality. The problem is that when pages are requested the screen does not always display until there is some browser event.

An example is if I put a Javascript alert(...) statement within the page's script. The screen will blank and the message will display and when you click the ok the full page displays

Another example is the page goes blank when the user navigates. Click anywhere on the screen and the page will display.

It seems as if the pages are loading but the webbrowser control is locked and will not display anything until there is a user event.

DocumentCompleted() event does fire, within that event I have tried

        webBrowser.Invalidate();
        webBrowser.Update();
        webBrowser.Refresh();

But the page will not display until the user taps the screen with the stylus.


回答1:


Use the DocumentCompleted event of the WebBrowser control, like this:

private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    // hack for Windows CE based devices in order to get the page load right
    webBrowser.Width--;
    webBrowser.Width++;
}



回答2:


Figuring that an event was required in order to get the code to display I put this code at the end of the page load.

setTimeout(function(){
window.scrollTo(0,0);
}, 1);

That resolved the problem.



来源:https://stackoverflow.com/questions/22420027/webbrowser-does-not-display-page-until-an-event-occurs

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