WP7 WebBrowser control zoom

2019-01-23 17:37发布

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

4条回答
疯言疯语
2楼-- · 2019-01-23 17:57

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楼-- · 2019-01-23 17:58

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楼-- · 2019-01-23 18:09

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

查看更多
萌系小妹纸
5楼-- · 2019-01-23 18:15

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.

查看更多
登录 后发表回答