Use JavaScript for full-screen browser

Source: Internet
Author: User

Full screens in HTML 5 can now be used in browsers other than IE and opera, sometimes for
Full-screen API, game Ah, etc. are very useful. See the Common API first

1 Element.requestfullscreen ()

Function: Request an element full screen

2
document.getElementById ("MyCanvas"). Requestfullscreen ()

This is where the element ID goes to request fullscreen

3
Exit Full Screen
Document.cancelfullscreen ()

4
Document.fullscreen

Returns true if the user is in full-screen mode
5 document.fullscreenelement
Returns the element that is currently in full-screen mode

The following code is to turn on full screen mode:

    1. Function fullscreen (element)  {  
    2.    if (element.requestfullscreen)  {  
    3.     element.requestfullscreen ();   
    4.   } else if ( element.webkitrequestfullscreen )  {  
    5.      Element.webkitrequestfullscreen ();   
    6.   } else < span class= "keyword" >if (element.mozrequestfullscreen)  {  
    7.      element.mozrequestfullscreen ();   
    8.   }  
    9. }   



    The following code is the entire page called full-screen mode  
  var html = document.documentelement; 
Fullscreen (HTML);  
   The following is for the specified element, such as  
  var canvas = document.getElementById (' MyCanvas ');  
fullscreen (canvas);  
   If you want to cancel, also:  
  

    1. // the helper function  
    2. Function fullscreencancel ()  {  
    3.   if ( Document.requestfullscreen)  {  
    4.      Document.requestfullscreen ();   
    5.   } else if (document .webkitrequestfullscreen )  {  
    6.     document.webkitrequestfullscreen ();   
    7.   } else if (document .mozrequestfullscreen)  {  
    8.     document.mozrequestfullscreen ();   
    9.   }   
    10. }  
    11.   
    12.   
    13. fullscreencancel ();   



But to be honest, there's a problem with full screens, which can easily lead to deception, such as
http://feross.org/html5-fullscreen-api-attack/, which has a good demo,
To cheat, such as a link to write a http://www.bankofamerica.com, people think is the Bank of America,
A bit in, because using the full-screen API will deceive people

  1. $ (' HTML '). On (' click KeyPress ', ' a ', function (event) {
  2. //Do not respond to true a-href click events
  3. Event.preventdefault ();
  4. Event.stoppropagation ();
  5. //Trigger fullscreen
  6. if (elementprototype.requestfullscreen) {
  7. Document.documentElement.requestFullscreen ();
  8. } Else if (elementprototype.webkitrequestfullscreen) {
  9. Document.documentElement.webkitRequestFullScreen (Element.allow_keyboard_input);
  10. } Else if (elementprototype.mozrequestfullscreen) {
  11. Document.documentElement.mozRequestFullScreen ();
  12. } Else {
  13. //  
  14. }
  15. //Show fake UI
  16. $ (' #menu, #browser '). Show ();
  17. $ (' #target-site '). Show ();
  18. });



Detailed code can be downloaded in Https://github.com/feross/fullscreen-api-attack

Use JavaScript for full-screen browser

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.