Internet Explorer 7では、いくつかのプロパティ(マウス座標)は物理的なものとして扱われ、その他のものは論理的(オフセット)なものとして扱われます。これは本質的にWeb開発者にズーム状態を認識させたり計算させたりすることを必要としました。 IE8リリースでは、すべてのプロパティが論理的です。Internet Explorer 7でズームレベルを取得するにはどうすればよいですか? (JavaScript)
13
A
答えて
10
あなたは使用してそれを得ることができます。
var b = document.body.getBoundingClientRect();
alert((b.right - b.left)/document.body.clientWidth);
どうもありがとう@niclasnorgrenを!
8
また、IE 8をチェックインする必要がある場合は、window.screen.deviceXDPIとwindow.screen.deviceYDPIを使用できます。デフォルトは96 dpiです。ズームした場合、数字は大きくなります(ズーム150%のときは144)。
4
受け入れられた答えに小さな構文エラー(document.bodyの代わりにbody)があります。これもやっているようです。
var rect = document.body.getBoundingClientRect();
var zoomLevel = Math.round((rect.right-rect.left)/document.body.clientWidth * 100);
0
私はこれを別の投稿に貼り付けました。あなたはこれをここで得ることができます。 IE7でも動作します。
Auto-detect a screen resolution and change browser zoom with Javascript?
This will help to detect browser zoom tested on all browser
<script>
window.utility = function(utility){
utility.screen = {
rtime : new Date(1, 1, 2000, 12,00,00),
timeout : false,
delta : 200
};
utility.getBrowser = function(){
var $b = $.browser;
$.extend(utility.screen,$.browser);
utility.screen.isZoomed = false;
var screen = utility.screen;
screen.zoomf = screen.zoom = 1;
screen.width = window.screen.width;
screen.height = window.screen.height;
if($b.mozilla){ //FOR MOZILLA
screen.isZoomed = window.matchMedia('(max--moz-device-pixel-ratio:0.99), (min--moz-device-pixel-ratio:1.01)').matches;
} else {
if($b.chrome){ //FOR CHROME
screen.zoom = (window.outerWidth - 8)/window.innerWidth;
screen.isZoomed = (screen.zoom < .98 || screen.zoom > 1.02)
} else if($b.msie){//FOR IE7,IE8,IE9
var _screen = document.frames.screen;
screen.zoom = ((((_screen.deviceXDPI/_screen.systemXDPI) * 100 + 0.9).toFixed())/100);
screen.isZoomed = (screen.zoom < .98 || screen.zoom > 1.02);
if(screen.isZoomed) screen.zoomf = screen.zoom;
screen.width = window.screen.width*screen.zoomf;
screen.height = window.screen.height*screen.zoomf;
}
}
return utility.screen;
};
window.onresize = function(e){
utility.screen.rtime = new Date();
if (utility.screen.timeout === false) {
utility.screen.timeout = true;
setTimeout(window.resizeend, utility.screen.delta);
}
};
window.resizeend = function() {
if (new Date() - utility.screen.rtime < utility.screen.delta) {
setTimeout(window.resizeend, utility.screen.delta);
} else {
utility.screen.timeout = false;
utility.screen = utility.getBrowser();
if(window.onresizeend) window.onresizeend (utility.screen);
if(utility.onResize) utility.onResize(utility.screen);
}
};
window.onresizeend = function(screen){
if(screen.isZoomed)
$('body').text('zoom is not 100%');
else{
$('body').text('zoom is 100% & browser resolution is'+[screen.width+'X'+screen.height]);
}
};
$(document).ready(function(){
window.onresize();
});
return utility;
}({});
</script>
関連する問題
- 1. Internet Explorer 7/8にFirebug Lite拡張機能を追加するにはどうすればよいですか?
- 2. JavaScriptを使用してmaps.google.comでズームレベルを取得するにはどうすればよいですか?
- 3. innerHTMLなしでInternet Explorer 5で表を編集するにはどうすればよいですか?
- 4. Internet Explorer 7 Javascriptの問題?
- 5. UIScrollViewで現在のズームレベルを取得するにはどうすればよいですか?
- 6. Internet Explorerデバッガ - どうすれば停止できますか?
- 7. Internet Explorer 11でCSSを有効にするにはどうすればよいですか?
- 8. スクリプトタグのInternet Explorer 10を検出するにはどうすればよいですか?
- 9. Internet ExplorerでUL/LI要素の右端を削除するにはどうすればよいですか?
- 10. Internet ExplorerでGCM/FCM通知を受信するにはどうすればよいですか?
- 11. Internet ExplorerでImageMapコントロールの青色の枠線を削除するにはどうすればよいですか?
- 12. Internet ExplorerでfullCalendarを実行するにはどうすればよいですか?
- 13. フラッシュ以外のアドオンなしでInternet Explorerを起動するにはどうすればよいですか?
- 14. Internet Explorerでブラウザイベントを監視するにはどうすればよいですか?
- 15. Internet Explorerでこの空白を取り除くにはどうすればいいですか?
- 16. アルファフィルタのintとして不透明度値を取得するにはどうすればよいですか? Internet Explorerの不透明度については
- 17. 現在のGoogleマップのズームレベルを取得するにはどうすればよいですか?
- 18. Internet Explorer 7 CSS
- 19. WatiNおよびInternet Explorer 7
- 20. Internet Explorer BHOエクステンションに子ノードを追加するにはどうすればよいですか?
- 21. Internet ExplorerでResponsiveSlidesスライドショーを動作させるにはどうすればよいですか?
- 22. IE7モードでInternet Explorer 9をデフォルトで開くにはどうすればよいですか?
- 23. PowershellからInternet Explorerの実行中のインスタンスの古典的なInternet Explorer COMオートメーションオブジェクトにアクセスするにはどうすればよいですか?
- 24. Internet Explorerのスクリプトエラーを検出するにはどうすればよいですか?
- 25. 背景アタッチメントのCSSスタイルを変更するにはどうすればよいですか?Internet Explorer Edgeのみ
- 26. Windows 7でInternet Explorer 7のテストとJavaScriptのデバッグを行う方法は?
- 27. Internet Explorer用のXSLドキュメントにCSSスタイルシートを含めるにはどうすればよいですか?
- 28. JavaScriptを使用してPhotoshopでズームレベルを制御するにはどうすればよいですか?
- 29. ブラウザがInternet Explorerの場合、JavaScriptコードが実行されないようにするにはどうすればよいですか?
- 30. Windows 7でTest-NetConnectionなどのPowerShell 4コマンドレットを取得するにはどうすればよいですか?
も参照してくださいhttp://stackoverflow.com/questions/1713771/how-to-detect-page-zoom-level-in-all-modern-browsers – ripper234