WP7 WebBrowser control zoom

后端 未结 4 909
花落未央
花落未央 2020-12-16 02:42

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

相关标签:
4条回答
  • 2020-12-16 03:15

    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;
        }
    
    0 讨论(0)
  • 2020-12-16 03:17

    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.

    0 讨论(0)
  • 2020-12-16 03:31

    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

    0 讨论(0)
  • 2020-12-16 03:38

    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.

    0 讨论(0)
提交回复
热议问题