Is there a way I can send a key stroke to the browser from JavaScript? For example: I would like to trigger the key F11 through JavaScript so that my browser goes to theater mode.
-
Related question, http://stackoverflow.com/questions/596481/simulate-javascript-key-events . – Juho Vepsäläinen Dec 27 '10 at 11:52
3 Answers
No. You cannot send keystrokes to the browser with just pure javascript.
And the world is safe that way. Otherwise, the first thing i will do is if browser==firefox SendKeys(Alt + (T + I + S + W) and copy all the stored passwords
But if your intention is to have the browser in full screen mode (and you gave a legitimate reason to do so, like oprning a window with photos for slideshow for instance) you can
- Open a pop up without the toolbars, address bar, status bar etc
or - Use flash/silverlight to open a full screen view (like in YouTube)

- 18,126
- 4
- 62
- 76
-
Thanks for the reply. Opening a window without toolbar is better. I tried to create the script which works. – clklachu Dec 27 '10 at 12:39
You can't. I presume "theater mode" means making the browser window fullscreen. Put simply, you cannot do this. It would be the source of enormous security flaws and usability problems if a website owner could do things like that to the browser window.
Would you like your browser to be continually jumping into fullscreen mode at the whim of the creator of a website?

- 233,373
- 50
- 316
- 318
-
Thanks for the reply. My scenario is, when the user clicks the fullscreen button in my website, it should move to fullscreen mode. – clklachu Dec 27 '10 at 12:43
As suggested by Nivas, I'm just posting the code snippet which i tried and was successful in achieving the fullscreen through javascript.
function fullscreen() {
params = 'width=' + screen.availWidth;
params += ', height=' + screen.availHeight;
params += ', fullscreen=yes';
params += ', status=no,titlebar=no,location=0,top=0, left=0';
window.open(window.location, "test", params);
}
I posted the code so that it would be a ready-made solution for one who is searching for fullscreen through javascript.

- 951
- 1
- 7
- 19