AnitaTang / js-hotkeys

Automatically exported from code.google.com/p/js-hotkeys
0 stars 0 forks source link

Ctrl S- need to block windows popup appearing. #60

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?
I expect when Ctrl+S, the binding will call to validate whether all
required fields are filled, then only submit form.

What version of the product are you using? On what operating system?

Please provide any additional information below.
Main issue is, when Ctrl+S, windows event popup asking me whether want to
save my testing.html. I don't want it to appear.
How to eliminate it? I try .preveneDefault(), not working...

Here's my full code:

<html>
<head>

    <script src="jquery-1.3.2.min.js"></script>
    <script src="jquery.hotkeys-0.7.9.min.js"></script>
    <script type="text/javascript">

        $(document).ready(function() {

$(window).keypress(function(event) {
  if ((event.which == 115 && event.ctrlKey)){
      //alert("Ctrl+S pressed");
      event.preventDefault();
  }
});

            jQuery(document).bind('keydown', 'Ctrl+s',
                   function(evt){ Create(); return false; });

        });

        function Create()
        {
            var f = document.frm

            if (f.txtQuestion.value.length == 0)
            {
                alert('Please enter Question.')
                f.txtQuestion.focus()
                return false
            }
            f.submit()
        }

    </script>
</head>
<body> 
    <form name="frm" method=post action="" >

      <input type=text name="txtQuestion" maxlength="255" class="field400"
value="">
      <input type=button value="Save" name="BtnSave" onclick="Create()"
class=text100>
    </form>
</body>
</html>

Original issue reported on code.google.com by askmen...@gmail.com on 13 Jul 2009 at 7:22

GoogleCodeExporter commented 8 years ago
 I use $(window).keypress to detect it. Found that the alert appear twice. Not sure
why the 'Ctrl S Pressed' appear twice.

Original comment by askmen...@gmail.com on 13 Jul 2009 at 7:27

GoogleCodeExporter commented 8 years ago
Hello, anyone able to help out?

Original comment by askmen...@gmail.com on 22 Jul 2009 at 9:00

GoogleCodeExporter commented 8 years ago
your code would work just ok if you catch the "keypress" not the "keydown" 
event. no 
need for preventDefault or stopPropagation just return false.

Original comment by nedko.iv...@gmail.com on 29 Sep 2009 at 9:20

GoogleCodeExporter commented 8 years ago
I see that if focus was on a textbox, in firefox the default popup will appear. 
$(
'input' ).blur(); all inputs resolve everything for me. Hope this could help 
somebody
else. Cheers

Original comment by d.aldrov...@gmail.com on 15 Oct 2009 at 10:58