Prev: Standalone .js file creates IE, and call javascript functions in the page
Next: Javascript pause or sleep thread execution
From: Krist on 11 Dec 2009 05:40 Hi All, In our web application we want to disable user from pressing CTRL key. and we want to implement this for IE, Firefox and if possible other browser. I have tried this code, doesn't work : <script type="text/javascript"> document.onkeyup = KeyCheck; function KeyCheck() { var KeyID = (window.event) ? event.keyCode : e.keyCode; if ( KeyID == 17) { alert("Test Alert System"); } } </script> Pls help me to fix the code... Thank you very much, Krist
From: The Natural Philosopher on 11 Dec 2009 05:45 Krist wrote: > Hi All, > > In our web application we want to disable user from pressing CTRL key. > and we want to implement this for IE, Firefox and if possible other > browser. > > I have tried this code, doesn't work : > > <script type="text/javascript"> > document.onkeyup = KeyCheck; > function KeyCheck() > { > var KeyID = (window.event) ? event.keyCode : e.keyCode; > if ( KeyID == 17) { > alert("Test Alert System"); > } > } > </script> > > Pls help me to fix the code... > > Thank you very much, > Krist > I think you will find that since javascript only works INSIDE a browser, it can only deal with key presses that the operating system passes through to the browser. CTTRL is not necessarily one of those, since at least on windows, you NEED Ctrl-Alt-del to maintain normal operation of the computer.;-0
From: Amrit Ranjan on 11 Dec 2009 07:01 On Dec 11, 3:45 pm, The Natural Philosopher <t...(a)invalid.invalid> wrote: > Krist wrote: > > Hi All, > > > In our web application we want to disable user from pressing CTRL key. > > and we want to implement this for IE, Firefox and if possible other > > browser. > > > I have tried this code, doesn't work : > > > <script type="text/javascript"> > > document.onkeyup = KeyCheck; > > function KeyCheck() > > { > > var KeyID = (window.event) ? event.keyCode : e.keyCode; > > if ( KeyID == 17) { > > alert("Test Alert System"); > > } > > } > > </script> > > > Pls help me to fix the code... > > > Thank you very much, > > Krist > > I think you will find that since javascript only works INSIDE a browser, > it can only deal with key presses that the operating system passes > through to the browser. > > CTTRL is not necessarily one of those, since at least on windows, you > NEED Ctrl-Alt-del to maintain normal operation of the computer.;-0 Hi your code will work fine with IE, Safari, Chrome, Opera except Mozilla. It is because the function definition KeyCheck() should look like KeyCheck(e). Actually Mozilla passes event object as an arguments. I had added "e" with your code. Do you want to cancel this event? function KeyCheck(e) { var KeyID = (window.event) ? event.keyCode : e.keyCode; //e is not global variable is is the argument if ( KeyID == 17) { alert("Test Alert System"); } }
From: Krist on 11 Dec 2009 07:15 On 11 Des, 19:01, Amrit Ranjan <amri...(a)gmail.com> wrote: > On Dec 11, 3:45 pm, The Natural Philosopher <t...(a)invalid.invalid> > wrote: > > > > > > > Krist wrote: > > > Hi All, > > > > In our web application we want to disable user from pressing CTRL key.. > > > and we want to implement this for IE, Firefox and if possible other > > > browser. > > > > I have tried this code, doesn't work : > > > > <script type="text/javascript"> > > > document.onkeyup = KeyCheck; > > > function KeyCheck() > > > { > > > var KeyID = (window.event) ? event.keyCode : e.keyCode; > > > if ( KeyID == 17) { > > > alert("Test Alert System"); > > > } > > > } > > > </script> > > > > Pls help me to fix the code... > > > > Thank you very much, > > > Krist > > > I think you will find that since javascript only works INSIDE a browser, > > it can only deal with key presses that the operating system passes > > through to the browser. > > > CTTRL is not necessarily one of those, since at least on windows, you > > NEED Ctrl-Alt-del to maintain normal operation of the computer.;-0 > > Hi your code will work fine with IE, Safari, Chrome, Opera except > Mozilla. It is because the function definition KeyCheck() should look > like KeyCheck(e). Actually Mozilla passes event object as an > arguments. I had added "e" with your code. Do you want to cancel this > event? > > function KeyCheck(e) > { > var KeyID = (window.event) ? event.keyCode : e.keyCode; //e is not > global variable is is the argument > if ( KeyID == 17) { > alert("Test Alert System"); > } > > > > }- Sembunyikan teks kutipan - > > - Perlihatkan teks kutipan -- Sembunyikan teks kutipan - > > - Perlihatkan teks kutipan - Hi Sir, Thank you for your reply. further question.. To tell the page to run KeyCheck, I use this code : document.onkeyup = KeyCheck; How to make it conditionally call KeyCheck or KeyCheck(event) based on what browser it is running ? Thank you, Krist
From: Swifty on 11 Dec 2009 10:02 Krist wrote: > Hi All, > > In our web application we want to disable user from pressing CTRL key. > and we want to implement this for IE, Firefox and if possible other > browser. If you manage to disable me from pressing the Ctrl key, for goodness sake don't let my wife find out, otherwise she'd prevent me from pressing all the other keys. :-) There are some who would say that this is a good thing. -- Steve Swift http://www.swiftys.org.uk/swifty.html http://www.ringers.org.uk
|
Next
|
Last
Pages: 1 2 3 4 5 6 Prev: Standalone .js file creates IE, and call javascript functions in the page Next: Javascript pause or sleep thread execution |