3

I am trying to load a page on full screen mode the code below works but demands a click in the page i would like to do this on page load any help will be appreciate it!

code

 <!-- full screen mode-->
    <script type="text/javascript">

        function launchIntoFullscreen(element) {
            if (element.requestFullscreen) {
                element.requestFullscreen();
            } else if (element.mozRequestFullScreen) {
                element.mozRequestFullScreen();
            } else if (element.webkitRequestFullscreen) {
                element.webkitRequestFullscreen();
            } else if (element.msRequestFullscreen) {
                element.msRequestFullscreen();
            }
        }

  </script>   

calling function

  <script type="text/javascript">
       $(document).ready(function () {

           var myEl = document.getElementById('theBody');

           myEl.addEventListener('click', function () {

               launchIntoFullscreen(document.getElementById("theBody"));


           }, false);


       });

    </script>    
Carlos
  • 377
  • 5
  • 24

2 Answers2

1

This requires the user to click on myEl:

       myEl.addEventListener('click', function () {
           launchIntoFullscreen(document.getElementById("theBody"));
       }, false);

All you need is:

       launchIntoFullscreen(document.getElementById("theBody"));
KJ Price
  • 5,774
  • 3
  • 21
  • 34
  • Hi KJ Prince, thank you for your response. I tried that and nothing happens, i made some research and in order to make this work, i have to create an EventListener – Carlos Mar 09 '15 at 20:27
  • 1
    Wow, that's a new one to me. You are definitely right though. Check out this related question that seems to have some good answers to this http://stackoverflow.com/questions/9454125/javascript-request-fullscreen-is-unreliable. – KJ Price Mar 09 '15 at 20:36
  • Unfortunately, it looks like what you want to do is not possible, in Chrome at least. – KJ Price Mar 09 '15 at 20:37
1

This is an untested version. Since you're using jQuery, try the following.

$(document).ready(function() {
    var myEl = $("#theBody");
    myEl.on('click', function () {
        launchIntoFullscreen(myEl[0]);
    }).trigger("click");
});
lshettyl
  • 8,166
  • 4
  • 25
  • 31