2011-09-21 14 views
6

Tôi muốn làm cho trình duyệt của tôi toàn màn hình. Giống như khi chúng ta thực hiện sự kiện quan trọng F11. Tôi đã tìm thấy một số ví dụ nhưLàm thế nào để làm cho trình duyệt toàn màn hình bằng cách sử dụng sự kiện quan trọng F11 thông qua JavaScript

function maxwin() { 
    var wscript = new ActiveXObject("WScript.Shell"); 
    if (wscript!=null) { 
     wscript.SendKeys("{F11}"); 
    } 
} 

Không hoạt động trên mozilla hoặc bất kỳ trình duyệt mới nhất nào khác. Vui lòng cho tôi biết nếu có bất kỳ cách nào để phân loại vấn đề này.

Cảm ơn. (Trước.)

Trả lời

6

Không thể không có mã gốc hoặc tiện ích mở rộng của trình duyệt. ActiveXObject chỉ tồn tại trong trình duyệt IE.

+0

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

+0

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

+0

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

-1

bây giờ một ngày nó có thể (ít nhất là trình duyệt webkit tại Safari 5, chrome 16) với

webkitEnterFullscreen() 

Firefox 10 cũng làm việc. check this link

không có ý kiến ​​gì tức là đang làm trong chủ đề này

9

sử dụng mã này thay vì

var el = document.documentElement 
, rfs = // for newer Webkit and Firefox 
     el.requestFullScreen 
    || el.webkitRequestFullScreen 
    || el.mozRequestFullScreen 
    || el.msRequestFullScreen 
; 
if(typeof rfs!="undefined" && rfs){ 
    rfs.call(el); 
} else if(typeof window.ActiveXObject!="undefined"){ 
    // for Internet Explorer 
    var wscript = new ActiveXObject("WScript.Shell"); 
    if (wscript!=null) { 
    wscript.SendKeys("{F11}"); 
    } 
} 

Nguồn: How to make in Javascript full screen windows (stretching all over the screen)

trình và thử nghiệm trên Chrome, FF10 trên, IE 8 trên, Safari 5 ..

5

Đ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ó

+0

Tôi đã thử giải pháp khác. Câu trả lời hay nhất này, 100% hoạt động. – dns