最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Make google-chrome browser go fullscreen when page loads - Stack Overflow

programmeradmin0浏览0评论

Please consider answering this question here even if you mark it as a duplicate because for some reason I just can't get it to work with other solutions and though I tried to ask for help no one replied...

What I really want is to $(document).ready(function(){browser goes fullscreen}) but unfortunately it isn't working and I am desperate through trying to find a solution online because nothing appears to work! I have the js file well inserted in my main php file (console.log works) but it just won't load fullscreen no matter the lines of code...

If you can provide a solution to work in all browsers and with keys activated I would be really, really thankful. Otherwise I'll contempt myself with the google chrome answer. Thank you so much.

EDIT1:

I tried this

// mozilla proposal
element.requestFullScreen();
document.cancelFullScreen(); 

// Webkit (works in Safari and Chrome Canary)
element.webkitRequestFullScreen(); 
document.webkitCancelFullScreen(); 

// Firefox (works in nightly)
element.mozRequestFullScreen();
document.mozCancelFullScreen(); 

// W3C Proposal
element.requestFullscreen();
document.exitFullscreen();

The following one only under user interaction:

addEventListener("click", function() {
    var
          el = document.documentElement
        , rfs =
               el.requestFullScreen
            || el.webkitRequestFullScreen
            || el.mozRequestFullScreen
    ;
    rfs.call(el);
});

amongst others I can't find now and basically I have bined them with $(document).ready(function(){---}); but nothing happened.

Please consider answering this question here even if you mark it as a duplicate because for some reason I just can't get it to work with other solutions and though I tried to ask for help no one replied...

What I really want is to $(document).ready(function(){browser goes fullscreen}) but unfortunately it isn't working and I am desperate through trying to find a solution online because nothing appears to work! I have the js file well inserted in my main php file (console.log works) but it just won't load fullscreen no matter the lines of code...

If you can provide a solution to work in all browsers and with keys activated I would be really, really thankful. Otherwise I'll contempt myself with the google chrome answer. Thank you so much.

EDIT1:

I tried this

// mozilla proposal
element.requestFullScreen();
document.cancelFullScreen(); 

// Webkit (works in Safari and Chrome Canary)
element.webkitRequestFullScreen(); 
document.webkitCancelFullScreen(); 

// Firefox (works in nightly)
element.mozRequestFullScreen();
document.mozCancelFullScreen(); 

// W3C Proposal
element.requestFullscreen();
document.exitFullscreen();

The following one only under user interaction:

addEventListener("click", function() {
    var
          el = document.documentElement
        , rfs =
               el.requestFullScreen
            || el.webkitRequestFullScreen
            || el.mozRequestFullScreen
    ;
    rfs.call(el);
});

amongst others I can't find now and basically I have bined them with $(document).ready(function(){---}); but nothing happened.

Share Improve this question edited Dec 12, 2013 at 1:59 Dean Taylor 42.1k3 gold badges32 silver badges53 bronze badges asked Dec 11, 2013 at 20:42 user3050963user3050963 2751 gold badge3 silver badges8 bronze badges 12
  • please provide some code for us to investigate why it fails. – Gotschi Commented Dec 11, 2013 at 20:44
  • 2 For security reasons you might find that actions such as "full-screen" might only be available if they are enacted as a direct result of a user action i.e. "click". – Dean Taylor Commented Dec 11, 2013 at 20:45
  • @Gotschi I have no code at the moment, I have ran over so much attempts and switch things that I don't know which one to put here but I'll edit the question and try to go over this if it helps. – user3050963 Commented Dec 11, 2013 at 20:46
  • I don't believe you can go fullscreen on page load. The user must initiate this action. Could you imagine the fullscreen popup windows all over the Internet if this would be allowed to happen without the user explicitly initiating it? – HaukurHaf Commented Dec 11, 2013 at 20:47
  • @DeanTaylor Ty for the tip Dean but I was actually aware of this and it isn't the problem... Code that described this feature didn't work and the same happened to code made to "force" the fullscreen. – user3050963 Commented Dec 11, 2013 at 20:48
 |  Show 7 more ments

1 Answer 1

Reset to default 5

The short answer is you can't.

I have tested using this code.

In Firefox is outputs this warning in the console - frankly I was expecting this kind of warning from all browsers, however it seems currently only Firefox implements this.

Request for full-screen was denied because Element.mozRequestFullScreen() was not called from inside a short running user-generated event handler. 

As I stated in my ment:

For security reasons you might find that actions such as "full-screen" might only be available if they are enacted as a direct result of a user action i.e. "click"

Well it's true. Get the user to click something (or take some other user event) to make then call the full-screen functions.

Browsers Tested (navigator.userAgent):

  • Chrome 31: "5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"
  • Firefox 25: "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0"
  • IE 11: "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3; rv:11.0) like Gecko"
发布评论

评论列表(0)

  1. 暂无评论