开发者

Simulate keyboard keypress with Jquery

Is it possible to simulate a keypress when I click a div? Something like:

$("mydiv").click(function(){
 Presskey->F5
});

Actually the key I'm trying to simulate is F11, so people could press the div and the window would fullscreen. I've searched this and I know it's not possible to make window fullscreen without the user "permission" but in this case he would pre开发者_C百科ss the div as he pressed the key. The fact is not everyone knows about F11 (I know I could always put "Press F11 for fullscreen"). Thanks'


Yes you can simulate F11 being pressed, but you can't simulate what that does, which is a native browser function (as it would only have an effect in the JavaScript VM area), and not one triggered by JavaScript.

"Press F11 for fullscreen" is your best option here, think of the security issues if you could trigger any browser behavior from JavaScript, e.g. Ctrl+S, etc.

As an aside, this is true even in other areas, for example you can simulate a click event on an anchor and it'll trigger all the JavaScript goodness hooked up to it...but it won't actually follow the link, some (most) things in a browser happen above the JavaScript level, where you don't have access to anything.


You cannot programmatically enforce fullscreen, nor can you with keypresses simulate actions which aren't otherwise accessible through JavaScript.

If you are working with HTML video, you may want to have a look at this, which is not cross-browser supported.


There is a security issue with this as it can be used by some malicious scripts to exploit it as a method to confuse user and make them do some things that they are not supposed to do... or forcing them to one website ( remember that most of web users aren't that smart and 70% of them are just stupid)


Flash?

http://forums.swishzone.com/index.php?showtopic=45156&st=0&p=196058&#entry196058

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜