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. JavaScriptを使用してmaps.google.comでズームレベルを取得するにはどうすればよいですか?
- 2. Internet Explorer 7/8にFirebug Lite拡張機能を追加するにはどうすればよいですか?
- 3. Internet Explorer 7 Javascriptの問題?
- 4. UIScrollViewで現在のズームレベルを取得するにはどうすればよいですか?
- 5. 現在のGoogleマップのズームレベルを取得するにはどうすればよいですか?
- 6. Internet Explorerデバッガ - どうすれば停止できますか?
- 7. Internet Explorerでこの空白を取り除くにはどうすればいいですか?
- 8. アルファフィルタのintとして不透明度値を取得するにはどうすればよいですか? Internet Explorerの不透明度については
- 9. Internet ExplorerでImageMapコントロールの青色の枠線を削除するにはどうすればよいですか?
- 10. Internet ExplorerでfullCalendarを実行するにはどうすればよいですか?
- 11. Internet ExplorerでUL/LI要素の右端を削除するにはどうすればよいですか?
- 12. フラッシュ以外のアドオンなしでInternet Explorerを起動するにはどうすればよいですか?
- 13. Internet Explorer BHOエクステンションに子ノードを追加するにはどうすればよいですか?
- 14. Internet ExplorerでResponsiveSlidesスライドショーを動作させるにはどうすればよいですか?
- 15. JavaScriptを使用してPhotoshopでズームレベルを制御するにはどうすればよいですか?
- 16. IE7モードでInternet Explorer 9をデフォルトで開くにはどうすればよいですか?
- 17. Internet Explorerのスクリプトエラーを検出するにはどうすればよいですか?
- 18. Internet Explorer用のXSLドキュメントにCSSスタイルシートを含めるにはどうすればよいですか?
- 19. Windows 7でTest-NetConnectionなどのPowerShell 4コマンドレットを取得するにはどうすればよいですか?
- 20. Internet Explorer 7 CSS
- 21. WatiNおよびInternet Explorer 7
- 22. PowershellからInternet Explorerの実行中のインスタンスの古典的なInternet Explorer COMオートメーションオブジェクトにアクセスするにはどうすればよいですか?
- 23. Windows 7でInternet Explorer 7のテストとJavaScriptのデバッグを行う方法は?
- 24. XPとVistaでQuick Launchフォルダを確実に取得するにはどうすればよいですか?
- 25. ブラウザがInternet Explorerの場合、JavaScriptコードが実行されないようにするにはどうすればよいですか?
- 26. Windows Phone 7でダウンロードしたファイルをプログラムで取得するにはどうすればよいですか?
- 27. IEのsIFR埋め込みタグでclickイベントを取得するにはどうすればよいですか?
- 28. Internet Explorer 7 +で使用するためのActive Xコントロールを作成するにはどうすればよいですか?
- 29. Internet Explorerのプロパティのヌル値にJavascriptが壊れています - これを無視するにはどうすればよいですか?
- 30. Internet ExplorerをテストするJavaScript
も参照してくださいhttp://stackoverflow.com/questions/1713771/how-to-detect-page-zoom-level-in-all-modern-browsers – ripper234