c#或Javascript设置窗口缩放100% [英] c# or Javascript set window zoom on 100%

查看:75
本文介绍了c#或Javascript设置窗口缩放100%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Visual C#或JavaScript中以编程方式放大WebBrowser控件中的网页?

How do you programatically zoom in on a web page in a WebBrowser control in Visual C# or with JavaScript?

这是我的尝试:

if (window.screen.width=='600')
{
document.write ('<body bgcolor="#4FB8CB" style="zoom: 55%">')
;}
else if
(window.screen.width=='800')
{
document.write ('<body bgcolor="#4FB8CB" style="zoom: 75%">')
;}
else if
(window.screen.width=='1024')
{
document.write ('<body bgcolor="#4FB8CB" style="zoom: 100%">')
;}
else if
(window.screen.width=='1152')
{
document.write ('<body bgcolor="#4FB8CB" style="zoom: 110%">')
;}
else if
(window.screen.width=='1280')
{
document.write('<body bgcolor="#4FB8CB" style="zoom: 127%">')
;}
else if
(window.screen.width=='1600')
{
document.write('<body bgcolor="#4FB8CB" style="zoom: 155%">')
;}

推荐答案

Firefox&与IE特定的zoom属性等效的Chrome(Webkit)分别是-moz-transform和-webkit-transform.

The Firefox & Chrome (Webkit) equivalents to the IE-specific zoom property are, respectively, -moz-transform and -webkit-transform.

示例代码:

.zoomed-element {
    zoom: 1.8;
    -moz-transform: scale(1.8);
    -webkit-transform: scale(1.8);
}

您必须更加小心使用Javascript(首先测试是否存在),但这是操作它们的方式:

You'd have to be a bit more careful with Javascript (test for existence first), but here's how you'd manipulate them:

el.style.zoom = 1.9;
el.style.MozTransform = 'scale(1.9)';
el.style.WebkitTransform = 'scale(1.9)';

这篇关于c#或Javascript设置窗口缩放100%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆