javascript 强制网页以 100% 缩放打开(在 IE8 中)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4718435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
force webpage to open in 100% zoom (in IE8)
提问by Dani-Br
I have a website which works well with any zoom on FireFox/Chrome/Opera/Safari... but on Internet Explorer the site looks good only with 100% zoom. in IE7 the default zoom is 100%, but in IE8 the default zoom is 125%, so if you are using IE8 you need to press ctrl+0. I have used PIE.htc from http://www.css3pie.comfor support CSS3 on IE.
我有一个网站,它在 FireFox/Chrome/Opera/Safari 上的任何缩放都可以很好地工作......但在 Internet Explorer 上,该网站只有在 100% 缩放时才看起来不错。在 IE7 中默认缩放为 100%,但在 IE8 中默认缩放为 125%,因此如果您使用的是 IE8,则需要按 ctrl+0。我在 IE 上使用了来自http://www.css3pie.com 的PIE.htc来支持 CSS3。
Is there any JavaScript code or meta tag that controls the view size? I'll use it for IE only, of course.
是否有任何 JavaScript 代码或元标记来控制视图大小?当然,我只会将它用于 IE。
采纳答案by Tim Medora
http://msdn.microsoft.com/en-us/library/ms531189(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/ms531189(v=vs.85).aspx
"Windows Internet Explorer 8. The -ms-zoom attribute is an extension to CSS, and can be used as a synonym for zoom in IE8 mode."
“Windows Internet Explorer 8。-ms-zoom 属性是 CSS 的扩展,可以用作 IE8 模式下缩放的同义词。”
Having said that, I haven't tried it to know how it behaves, and you shouldn't force a particular size on a user (as @Brad stated).
话虽如此,我还没有尝试了解它的行为方式,并且您不应该对用户强制使用特定大小(如@Brad 所述)。
All modern browsers do a nice job of scaling things smoothly both up and down, so I wouldn't worry about it too much.
所有现代浏览器都在向上和向下平滑缩放方面做得很好,所以我不会太担心。
EDIT: your site looks fine in Chrome and IE8 on my machine (in which it opens at 100% on my machine anyway, so check your browser settings. This whole discussion may be moot).
编辑:您的网站在我的机器上的 Chrome 和 IE8 中看起来不错(无论如何,它在我的机器上以 100% 的速度打开,因此请检查您的浏览器设置。整个讨论可能没有实际意义)。
回答by Brad
No, this isn't possible. User preferences are up to the user, and even if you could find a way around it, you shouldn't.
不,这是不可能的。用户偏好取决于用户,即使您可以找到解决方法,也不应该这样做。
It is up to the user to decide how they want their pages zoomed, not you. Keep in mind, this is often due to folks that can't see well (or can barely see at all), and they're much more interested in being able to read a page than how good your scaled graphics look.
由用户决定他们希望如何缩放页面,而不是您。请记住,这通常是由于人们看不清(或几乎看不到),并且他们对能够阅读页面的兴趣比缩放图形的外观更感兴趣。
回答by Luis Fajardo
It works on Chrome
<script> document.firstElementChild.style.zoom = "reset"; </script>With this I prevent the user to zoom in on the page
<script> $(document).ready(function () { $(document).keydown(function (event) { if (event.ctrlKey == true && (event.which == '107' || event.which == '109' || event.which == '187' || event.which == '189')) { event.preventDefault(); } }); $(window).bind('mousewheel DOMMouseScroll', function (event) { if (event.ctrlKey == true) { event.preventDefault(); } }); }) </script>
它适用于 Chrome
<script> document.firstElementChild.style.zoom = "reset"; </script>有了这个,我可以防止用户放大页面
<script> $(document).ready(function () { $(document).keydown(function (event) { if (event.ctrlKey == true && (event.which == '107' || event.which == '109' || event.which == '187' || event.which == '189')) { event.preventDefault(); } }); $(window).bind('mousewheel DOMMouseScroll', function (event) { if (event.ctrlKey == true) { event.preventDefault(); } }); }) </script>
回答by Dani-Br
Thanks to Brad and to Tim Medora.
I think the "-ms-zoom" property was helpful.
感谢布拉德和蒂姆梅多拉。
我认为“-ms-zoom”属性很有帮助。
Apple developed a good solution for Safari on iPhone and iPod :
苹果为 iPhone 和 iPod 上的 Safari 开发了一个很好的解决方案:
<meta name="viewport" content="initial-scale=1.0 , minimum-scale=0.5 , maximum-scale=1.5" />
see details here.
请参阅此处的详细信息。
Mobile Firefox supports this meta tag too.
Also, this tag could be useful to desktop browsers, but they don't support it yet.
Mobile Firefox 也支持这个元标记。
此外,此标签可能对桌面浏览器有用,但它们尚不支持。

