2

I want to alert to user if CAPS LOCK is ON when HTML page get load.

I have tried search in google and got multiple views from people some are saying possible some are saying not possible.

I have code which will alert to user only when they type something through keyboard.

document.onkeypress = function ( e ) {
    e = e || window.event;
    var s = String.fromCharCode( e.keyCode || e.which );
    if ( s.toUpperCase() === s && !e.shiftKey ) { // incomplete: shift + caps MAY =  lowercase
        alert('caps is on')
    }
}

Working.

Is it possible to alert on load of HTML page?

PS:

Check Scroll Lock, Num Lock & Caps Lock in JavaScript on Page Load

http://dougalmatthews.com/2008/Jul/02/javascript-detecting-caps-lock/

Community
  • 1
  • 1
SK.
  • 4,174
  • 4
  • 30
  • 48
  • 1
    Why did you link to a duplicate in your question? – cookie monster Jan 16 '14 at 21:54
  • 1
    You have your answer in the question you linked to... – Bill Jan 16 '14 at 21:54
  • ...and it looks like there are a bunch of other potential duplicates in the **Related** list to the right. – cookie monster Jan 16 '14 at 21:55
  • @cookiemonster in first link is saying...not possible... so i am confused....trying to find out possible or not... – SK. Jan 16 '14 at 21:56
  • @BillyMathews so are you saying its not possible to check CAPS LOCK onload of html page... – SK. Jan 16 '14 at 21:58
  • 1
    If you don't believe the answer given there, why would you believe an answer given here? – cookie monster Jan 16 '14 at 21:58
  • http://dougalmatthews.com/2008/Jul/02/javascript-detecting-caps-lock/ –  Jan 16 '14 at 21:58
  • @cookiemonster so its not about believe... as you can see that question is **answered Jan 30 '12 at 6:19**... 2 years back... may be someone has found out a way to check this thing... right? – SK. Jan 16 '14 at 22:00
  • Why do you need it on page load in the first place? What are you ultimately trying to do that can't wait for the user to offer a key event? – cookie monster Jan 16 '14 at 22:10
  • good question.. :) so basically i am automating a application where i am take input from excel file and user will not be type anything on that webpage... so i want to keep a check in starting itself... – SK. Jan 16 '14 at 22:20
  • if they aren't typing, what's it matter anyway? – dandavis Jan 16 '14 at 22:24
  • If capslock is not then upper case invoice number converts into lower case once in while... – SK. Jan 16 '14 at 22:33
  • Check if [this plugin](https://github.com/nosilleg/capslockstate-jquery-plugin) helps. Otherwise your solution is the way to go. Like [this question](http://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript). – Robert Fricke Jan 16 '14 at 22:01

0 Answers0