Trong Internet Explorer 7 một số thuộc tính (tọa độ chuột) được coi là vật lý trong khi các thuộc tính khác là logic (offset). Điều này chủ yếu yêu cầu các nhà phát triển web phải nhận thức hoặc tính toán trạng thái zoom. Trong IE8, tất cả các thuộc tính đều hợp lý.Cách lấy mức thu phóng trong Internet Explorer 7? (javascript)
Trả lời
Bạn có thể lấy nó bằng cách sử:
var b = document.body.getBoundingClientRect();
alert((b.right - b.left)/document.body.clientWidth);
Thanks a lot @niclasnorgren!
Ngoài ra, nếu bạn cần kiểm tra trong IE 8, bạn có thể sử dụng window.screen.deviceXDPI và window.screen.deviceYDPI. Giá trị mặc định là 96 dpi và nếu bạn được phóng to, số sẽ lớn hơn (còn 144 khi được phóng to 150%)
cảm ơn, đó chỉ là những gì tôi cần để tìm "tỷ lệ thu phóng" :-) – naivists
window.screen.deviceXDPI hoạt động đáng tin cậy trong các chế độ mô phỏng của IE9 cho IE8, IE7. Phương thức getBoundingClientRect() trả về 100% trong tất cả các chế độ thu phóng. – ddotsenko
Lưu ý rằng screen.deviceXDPI chỉ dành cho IE chứ không phải trong Chrome. –
Có lỗi cú pháp nhỏ (thân thay vì document.body) trên câu trả lời được chấp nhận. Điều này dường như làm các trick cũng có.
var rect = document.body.getBoundingClientRect();
var zoomLevel = Math.round((rect.right-rect.left)/document.body.clientWidth * 100);
tôi đã đăng giải pháp cho bài đăng này trên một bài đăng khác mà bạn có thể tải tại đây. cũng sẽ hoạt động trong 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. Cách đặt mức thu phóng trong bản đồ google
- 2. Cách phát hiện mức thu phóng trang trong IE 8?
- 3. jquery-ui-map cách đặt mức thu phóng
- 4. Cách tìm mức thu phóng hiện tại trong Google Map?
- 5. Doc-type Đã nhận xét trong Internet Explorer 7
- 6. Vấn đề nhân bản jQuery 1.6.4 trong Internet Explorer 7
- 7. Google Maps v2 Đặt mức thu phóng
- 8. Vấn đề với JSON trong Internet Explorer 7
- 9. Lấy giá trị của một hộp SELECT trong Internet Explorer
- 10. cách thiết lập mức thu phóng bằng css
- 11. Cách lấy mức thu phóng hiện tại từ bản đồ google cho ios?
- 12. Cài đặt mức thu phóng trên trình duyệt di động
- 13. javascript "window.open" Mã sẽ không làm việc trong Internet Explorer 7 hoặc 8
- 14. Tối ưu hóa Javascript cho Internet Explorer
- 15. addEventListener trong Internet Explorer
- 16. cloneNode trong internet explorer
- 17. trang web thử nghiệm với internet explorer 7
- 18. bỏ qua iframe internet explorer 7 khi quay lại
- 19. setTimeout Internet Explorer
- 20. Internet Explorer 9 VHD
- 21. Đặt mức thu phóng tối thiểu cho cắt xén UIImagePickerController
- 22. Đặt mức thu phóng tối thiểu cho MapView
- 23. Thay đổi biểu tượng dựa trên mức thu phóng
- 24. Cách kích hoạt script.onerror trong Internet Explorer?
- 25. Javascript/CSS: đặt (firefox) mức thu phóng của khung nội tuyến?
- 26. Gỡ lỗi JavaScript trong Internet Explorer và Safari
- 27. Kiểm tra cú pháp javascript cho Internet Explorer
- 28. Làm cách nào để có được mức thu phóng hiện tại trong UIScrollView?
- 29. Bảng chiều cao hàng trong Internet Explorer
- 30. Android Google Maps v2 - đặt mức thu phóng cho myLocation
Xem thêm http://stackoverflow.com/questions/1713771/how-to-detect-page-zoom-level-in-all-modern-browsers – ripper234