WP7 WebBrowser control zoom

喜欢而已 提交于 2019-11-27 16:27:31

问题


Some pages are too small and hard to read in WebBrowser control, is zooming possible?


回答1:


If you have control of the html you can set the initial-scale of the viewport. More background here.

The IE Mobile Viewport on Windows Phone 7




回答2:


I went with the following hack:

BrowserControl.LoadCompleted += Browser_dohack;
private void Browser_dohack(object sender, NavigationEventArgs e)
    {
        string html = BrowserControl.SaveToString();
        string hackstring = "<meta name=\"viewport\" content=\"width=320,user-scalable=yes\" />";
        html = html.Insert(html.IndexOf("<head>", 0) + 6, hackstring);
        BrowserControl.NavigateToString(html);
        BrowserControl.LoadCompleted -= Browser_dohack;
    }



回答3:


Yes, assuming that you haven't prevented user scaling, you can tap to zoom or use pinching/stretching in the same way you can in the full browser.




回答4:


I went with setting a CSS3 scale-function on the transform-property of the body for the requested page, as I really know the layout and that it probably won't change anytime soon.

private void OnBrowserNavigated(object sender, NavigationEventArgs e) {
    var browser = (sender as WebBrowser);
    browser.InvokeScript("eval", 
        "var script = document.createElement('script');" +
        "script.src = \"https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.0.min.js\";" +
        "document.body.appendChild(script);" +
        "$('body').css('transform-origin', '0 0');" +
        "$('body').css('transform', 'scale(2.5)');"             
    );
}

I solved it via jQuery as I find it way more convenient. I could have done it via plain javascript as well, as the targeted browser is not in question here.



来源:https://stackoverflow.com/questions/4500062/wp7-webbrowser-control-zoom

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