0

I want to press any key suppose p or CTRL+F, Is it possible in javascript?

Note: I am not talking regarding key press event. Just like when user press any key in keyboard manually, I want key press using javacsript button.

vahid abdi
  • 9,636
  • 4
  • 29
  • 35
Sam
  • 433
  • 1
  • 10
  • 26

2 Answers2

4

If it possible in JS it would be a great security issue. This possibly only using JS + some OS tools. For example, WScript object for win platform.

var oShell = CreateObject("WSH.WScript");
oShell.SendKeys("^F");       // Ctrl+F
AlexS
  • 136
  • 4
  • Keep in mind, code I put above as example won't work without special security settings if the browser. And I didn't test it, it just as an idea. – AlexS Jan 31 '14 at 07:20
2

UPDATE

<input type="button" name="find" value="find" onclick="find();" />

This method may helps but it only works in firefox. chrome,safari,IE are not supported.


I understand your question, but Why should you need to do that? If you explain the reason, we may give some other suggestion.

But this is not possible in javascript to trigger a keypress without it happen actually. as alex said it may be an security issue.

Vignesh
  • 1,045
  • 2
  • 17
  • 34
  • Actually, I want to open find window (at browser when user press ctrl+F), I want to open that std window using javascript but its possible only in firefox and not other browser. If its not possible then finally I will go to implement my own search window in page. – Sam Jan 31 '14 at 08:31
  • instead of using browser's find box, I will go for my own search window. because I can take full control over the search. Anyway I'll tell you if I found any other way to achieve this. – Vignesh Jan 31 '14 at 09:15
  • 1
    Yes, I know, I have that code already, I told you it is working in firefox only – Sam Jan 31 '14 at 09:34
  • Me too Searched the web for the Past 30 minutes, I can't find anything useful other than the above. So I recommend You to create your own search. – Vignesh Jan 31 '14 at 09:46