I want to trigger f11 event of keyboard using javascript or jquery, can anyone tell me how to do this ?
Asked
Active
Viewed 4.4k times
7
-
1i want to trigger the same event which takes place when you press the f11 key on your keyboard.Please help. – Ravinder Singh Nov 24 '11 at 07:13
5 Answers
9
You can try using this one: http://andrew.hedges.name/experiments/fullscreen/

jacoor
- 760
- 5
- 9
-
2You should be aware though of the [differences](https://bugzilla.mozilla.org/show_bug.cgi?id=794468) between the Fullscreen API and the F11 fullscreen mode. – Tgr Nov 26 '14 at 02:36
-
1
5
You can't make people's computers type things through javascript. It violates the sandboxing environment of browsers. I assume that you are trying to make a window go full screen though. This SO question covers that.
How to make the window full screen with Javascript (stretching all over the screen)

Community
- 1
- 1

mrtsherman
- 39,342
- 23
- 87
- 111
4
I'm use this code:
function go_full_screen(){
var elem = document.documentElement;
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
}
}
<a href="#" onClick="go_full_screen();">Full Screen / Compress Screen</a>

Santos L. Victor
- 628
- 8
- 13
-1
To trigger event Keypress of F11 key like from keyboard, we need this..
Call this function on any event..
function mKeyF11(){
var e = new Event('keypress');
e.which = 122; // Character F11 equivalent.
e.altKey=false;
e.ctrlKey=false;
e.shiftKey=false;
e.metaKey=false;
e.bubbles=true;
document.dispatchEvent(e);
}
This is pure Javascript function and don't need jQuery to support it..
Update: Chrome prevents JavaScript key-press. Source
For chrome we can use the following.
if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen();
}

MarmiK
- 5,639
- 6
- 40
- 49
-3
Working code sample:
document.addEventListener("keyup", keyUpTextField, false);
function keyUpTextField (e)
{
var keyCode = e.keyCode;
if(keyCode==122){/*ejecutaAlgo*/}
}

Michał
- 2,456
- 4
- 26
- 33
-
OP do not want to execute something when f11 is pressed. He wants to simulate a key press. – litelite May 03 '17 at 19:48