2

Im just a newbie here in javascript .. Can somebody help me?

I need to full screen my page after i click a certain button/link for example .. i'm on page1 and when i click the button it will redirect me to page2 and will be automatically on full screen ..

i have this code for fullscreen ..

<script type="text/javascript">
// Find the right method, call on correct element
function launchFullScreen(element) {
 if(element.requestFullScreen) {
   element.requestFullScreen();
 } else if(element.mozRequestFullScreen) {
   element.mozRequestFullScreen();
 } else if(element.webkitRequestFullScreen) {
   element.webkitRequestFullScreen();
 }
 }
 </script>
 <button onclick =" launchFullScreen(document.documentElement);">fullscreen!</button>

---this code fullscreen only the current page, what i need is to navigate first to another page then fullscreen.. thanks in advance .. all responses/opinion are appreciated ..

Nixxhalle
  • 97
  • 3
  • 5
  • 10
  • 2
    If you need to load another page, and then go fullscreen, you have to add the script on the other page. You can't execute javascript for the next page on the current page. – adeneo Dec 23 '13 at 12:44
  • Hi @Nixxhalle, i too have the same requirement. if you had a solution for this please help me out with that. thank you – Shaik Dec 14 '19 at 07:48

2 Answers2

1

You should use instead of . In page 2 use this code:

<script>
    function launchFullScreen(element) {
        if(element.requestFullScreen) {
            element.requestFullScreen();
        } else if(element.mozRequestFullScreen) {
            element.mozRequestFullScreen();
        } else if(element.webkitRequestFullScreen) {
            element.webkitRequestFullScreen();
        }
    }
    window.onload = function () {
        launchFullScreen(document.documentElement);
    }
</script>

UPD: First of all sorry for misinformation. You can't fullscreen onload. Instead of window.onload you should use

<a href="page2" onclick="launchFullScreen(document.documentElement)"></a>

So while page is loading the browser will go into full screen mode.

kmakarychev
  • 731
  • 4
  • 14
  • U can not FullScreen browser on load http://stackoverflow.com/questions/16415784/to-call-dofullscreen-function-immediately-after-page-load – Somnath Kharat Dec 23 '13 at 12:54
  • or this http://stackoverflow.com/questions/10352236/full-screen-browser-window-on-load-document – Somnath Kharat Dec 23 '13 at 12:55
  • @SomnathKharat Of course you're right! Sorry. I'll update my answer. – kmakarychev Dec 23 '13 at 12:57
  • @kmakarychev .. i've tried the answer you gave. the page1 go to fullscreen but when the page2 loads.. it exited full screen .. sorry but can please be more specific .. thanks – Nixxhalle Dec 27 '13 at 11:25
0

You cannot Full Screen the Browser on page load.Full screen can be done only by user event.I was also having the same problem:

See Here and also this

https://wiki.mozilla.org/Gecko:FullScreenAPI#Suggested_UA_Policy

Community
  • 1
  • 1
Somnath Kharat
  • 3,570
  • 2
  • 27
  • 51