event.shiftKey is not detected in Fire fox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rakeshvthu
    New Member
    • May 2007
    • 27

    event.shiftKey is not detected in Fire fox

    hi all,

    we have a requirement to disable shift click and ctrl click.

    i have code:

    [CODE=javascript]document.onmous edown = shiftEnter;

    function shiftEnter(e) {
    if (event.shiftKey ) {
    alert("shift key is disabled");
    return false;
    }
    }
    [/CODE]
    this code is not working in Fire fox, please help.

    thanks,
    rakesh.
    Last edited by acoder; Jan 31 '08, 10:26 AM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    Moderator.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Browsers besides IE would use the 'e' while IE uses the global window.event.

      For a cross-browser solution, use something like:
      [code=javascript]if (!e) var e = window.event;[/code]then e will refer to the event.

      Comment

      • rakeshvthu
        New Member
        • May 2007
        • 27

        #4
        Originally posted by acoder
        Browsers besides IE would use the 'e' while IE uses the global window.event.

        For a cross-browser solution, use something like:
        [code=javascript]if (!e) var e = window.event;[/code]then e will refer to the event.
        Thanks for quick reply but It doesnt worked, can you suggest some other way of handling this, detecting event.shiftKey/event.ctrlKey events in Fire Fox.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by rakeshvthu
          Thanks for quick reply but It doesnt worked, can you suggest some other way of handling this, detecting event.shiftKey/event.ctrlKey events in Fire Fox.
          What does your code look like now?

          Comment

          • rakeshvthu
            New Member
            • May 2007
            • 27

            #6
            Originally posted by acoder
            What does your code look like now?
            Code:
            		function shiftEnter(e) {
            			if(navigator.userAgent.indexOf("MSIE") >= 0) { 
            				if ( event.shiftKey || event.ctrlKey ) {
            					alert("MSIE");
            				  var msg = "<bean:message key='home.player.operationNotAllowed' />";
            				  alert(msg);
            			 	  return false;
            				}
            			} else if(navigator.userAgent.indexOf("Firefox") >= 0) {
            				if(!e){
            					alert("Fire fox");
            					var e = window.event;
            					if( e.shifyKey || e.ctrlKey ){
            					  var msg = "<bean:message key='home.player.operationNotAllowed' />";
            					  alert(msg);
            				 	  return false;
            					}
            				}
            			}
            		}
            My code looks like this, please inform if anything wrong.

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Yes, there's no need for browser detection. Try this:
              [code=javascript]function shiftEnter(e) {
              if (!e) var e = window.event;
              if (e.shiftKey || e.ctrlKey ) {
              var msg = "<bean:mess age key='home.playe r.operationNotA llowed' />";
              alert(msg);
              return false;
              }
              }[/code]

              Comment

              • rakeshvthu
                New Member
                • May 2007
                • 27

                #8
                Originally posted by acoder
                Yes, there's no need for browser detection. Try this:
                [code=javascript]function shiftEnter(e) {
                if (!e) var e = window.event;
                if (e.shiftKey || e.ctrlKey ) {
                var msg = "<bean:mess age key='home.playe r.operationNotA llowed' />";
                alert(msg);
                return false;
                }
                }[/code]
                Sorry it is not working :( , is there any other different way to solve this problem.

                Comment

                • kvijayhari
                  New Member
                  • Jul 2007
                  • 24

                  #9
                  hi the following code worked nicely for me both in ie and firefox...

                  Code:
                  <script language=javascript>
                  document.onmousedown = shiftEnter;
                  function shiftEnter(e) {
                  	if (!e) var e = window.event;
                  	if (e.shiftKey || e.ctrlKey ) {
                        	var msg = "<bean:message key='home.player.operationNotAllowed' />";
                              alert(msg);
                              return false;
                         }
                  }
                  </script>
                  there is no reason the code shouldn't work for u..

                  do u get any errors or warnings??

                  if s please post the error or warning u r getting..

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    It works for me in Firefox. Can you post the rest of your code (if it's not too much). Maybe something else is affecting the script.

                    Edit: Thanks kvijayhari. You posted before I managed to finish typing.
                    Last edited by acoder; Feb 4 '08, 01:03 PM.

                    Comment

                    Working...