Điều này hiện có thể có trong các phiên bản mới nhất của Chrome, Firefox và IE (11).
Theo các con trỏ của Zuul trên this thread, tôi đã chỉnh sửa mã của mình để bao gồm IE11 và tùy chọn toàn màn hình bất kỳ yếu tố nào được chọn trên trang của bạn.
JS:
function toggleFullScreen(elem) {
// ## The below if statement seems to work better ## if ((document.fullScreenElement && document.fullScreenElement !== null) || (document.msfullscreenElement && document.msfullscreenElement !== null) || (!document.mozFullScreen && !document.webkitIsFullScreen)) {
if ((document.fullScreenElement !== undefined && document.fullScreenElement === null) || (document.msFullscreenElement !== undefined && document.msFullscreenElement === null) || (document.mozFullScreen !== undefined && !document.mozFullScreen) || (document.webkitIsFullScreen !== undefined && !document.webkitIsFullScreen)) {
if (elem.requestFullScreen) {
elem.requestFullScreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullScreen) {
elem.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
}
} else {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
}
HTML:
<input type="button" value="click to toggle fullscreen" onclick="toggleFullScreen(document.body)">
đâu "document.body" là yếu tố bất kỳ mà bạn muốn.
Cũng lưu ý rằng cố gắng chạy các lệnh toàn màn hình này từ bảng điều khiển có vẻ không hoạt động trên Chrome hoặc IE. Tôi đã thành công với Firebug trong Firefox mặc dù.
Một điều khác cần lưu ý là những "toàn màn hình" lệnh không có một thanh cuộn theo chiều dọc, bạn cần phải xác định này trong CSS: "quan trọng"
*:fullscreen
*:-ms-fullscreen,
*:-webkit-full-screen,
*:-moz-full-screen {
overflow: auto !important;
}
có vẻ là cần thiết để IE hiển thị nó
Nguồn
2014-08-11 14:42:20
Tôi tự hỏi có bao nhiêu thay đổi kể từ ngày 21 tháng 9 năm 2011? Facebook hiện nay (ngày 9 tháng 4 năm 2012) có chức năng tạo cửa sổ toàn màn hình (ít nhất là trong Chrome) và tôi vẫn đang sử dụng trình duyệt (và không flash) vì tôi có thể "Kiểm tra yếu tố" và thực hiện những thứ khác trên Chrome .. – JayC
Khá đúng: như @Treby chỉ ra có API toàn màn hình hiện đang nổi lên, do đó, điều này có thể không còn hợp lệ nữa. – Femi
Lưu ý rằng API toàn màn hình và F11 là [https://bugzilla.mozilla.org/show_bug.cgi?id=794468](không giống nhau). – Tgr