Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Window State to Fullscreen

Tags:

javascript

How can I change the web browser window state to Fullscreen in javascript(Like when user press F11)? I know how can I specify Window State of new Window that has been opened by Window.Open Method but I want to change the sate of current Window.

like image 609
Saleh Avatar asked May 26 '11 10:05

Saleh


3 Answers

You can't and you shouldn't do this.

  • You shouldn't do this, because it is a annoying user experience. So let the user decide and maybe ask him to press the button for fullscreen mode, but never force him.
  • You can't because the browser vendors disabled this feature for the reasons of my last point.

Minimal workarround would be to set the window size of the new window to something close to the screen resolution, but this could be tricky if the user has a dual screen.

like image 175
TheHippo Avatar answered Sep 30 '22 17:09

TheHippo


You can't.

Just ask for the user to press to press F11 and then detect if the user pressed it by checking the key code 122 (eg: keyup event) and comparing the size of the window with the size of the screen (screen.width/height and window.innerWidth/Height).

It's not perfect, specially for users with multiple screens.

like image 32
Diogo Gomes Avatar answered Sep 30 '22 17:09

Diogo Gomes


You can open a window without toolbars with JS:

window.open("http://www.stackoverflow.com","mywindow","menubar=0,resizable=1,toolbar=0,status=0,width=5000,height=5000");

It will probably be blocked by popup blockers, but that is the most you can do.

like image 42
Anze Jarni Avatar answered Sep 30 '22 17:09

Anze Jarni