Ctrl+S preventDefault in Chrome

As far as I can see, the secret sauce is, that Ctrl+S does NOT fire the keypress event, only the keydown event. Using jQuery.hotkeys: $(document).bind(‘keydown’, ‘ctrl+s’, function(e) { e.preventDefault(); alert(‘Ctrl+S’); return false; }); Only with jQuery: $(document).bind(‘keydown’, function(e) { if(e.ctrlKey && (e.which == 83)) { e.preventDefault(); alert(‘Ctrl+S’); return false; } }); Edit 2012.12.17 – jQuery.hotkeys …

Read more

Stop form from submitting , Using Jquery

Again, AJAX is async. So the showMsg function will be called only after success response from the server.. and the form submit event will not wait until AJAX success. Move the e.preventDefault(); as first line in the click handler. $(“form”).submit(function (e) { e.preventDefault(); // this will prevent from submitting the form. … See below code, …

Read more

When to use PreventDefault( ) vs Return false? [duplicate]

return false; return false; does 3 separate things when you call it: event.preventDefault() – It stops the browsers default behaviour. event.stopPropagation() – It prevents the event from propagating (or “bubbling up”) the DOM. Stops callback execution and returns immediately when called. Note that this behaviour differs from normal (non-jQuery) event handlers, in which, notably, return …

Read more

Bootstrap 3 – disable navbar collapse

After close examining, not 300k lines but there are around 3-4 CSS properties that you need to override: .navbar-collapse.collapse { display: block!important; } .navbar-nav>li, .navbar-nav { float: left !important; } .navbar-nav.navbar-right:last-child { margin-right: -15px !important; } .navbar-right { float: right!important; } And with this your menu won’t collapse. DEMO (jsfiddle) EXPLANATION The four CSS properties …

Read more

event.preventDefault() vs. return false (no jQuery)

The W3C Document Object Model Events Specification in 1.3.1. Event registration interfaces states that handleEvent in the EventListener has no return value: handleEvent This method is called whenever an event occurs of the type for which the EventListener interface was registered. […] No Return Value under 1.2.4. Event Cancelation the document also states that Cancelation …

Read more

React onClick and preventDefault() link refresh/redirect?

React events are actually Synthetic Events, not Native Events. As it is written here: Event delegation: React doesn’t actually attach event handlers to the nodes themselves. When React starts up, it starts listening for all events at the top level using a single event listener. When a component is mounted or unmounted, the event handlers …

Read more