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.