Skip to content

Instantly share code, notes, and snippets.

@chgeuer
Created August 29, 2012 15:12
Show Gist options
  • Select an option

  • Save chgeuer/3514112 to your computer and use it in GitHub Desktop.

Select an option

Save chgeuer/3514112 to your computer and use it in GitHub Desktop.
Change zoom level in a Windows 8 WebView control by injecting JavaScript
zoomLevel.TextChanged += (s, e) =>
{
Func<WebView, double, bool> zoom = (wv, zoomPercentage) =>
{
var script = string.Format(
"(function () {{ document.styleSheets[0]['rules'][0].style['zoom'] = {0}; }})();", zoomPercentage);
try
{
var result = wv.InvokeScript("eval", new string[] { script });
return true;
}
catch (Exception ex)
{
var notReady = ex.HResult == 0x80020101;
if (notReady) return false;
throw;
}
};
double zl;
if (double.TryParse(zoomLevel.Text, out zl))
{
zoom(webView, zl);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment