preventdefault

`return false` in an event handler attached by addEventListener or element.on*

╄→гoц情女王★ 提交于 2019-12-10 16:47:41
问题 Right let’s get this out the way first. Yes, I want to hide the context menu. No, I’m not trying to prevent someone lifting content off my page. Its intended use is input for an in-browser game and it will be limited to a specific area on the webpage. Moving from the ideological to the technical... var mouse_input = function (evt) { // ... return false; } document.onmousedown = mouse_input; // successful at preventing the menu. document.addEventListener('mousedown', mouse_input, true); //

jQuery preventDefault() not working inside AJAX call

牧云@^-^@ 提交于 2019-12-10 14:49:05
问题 So, I am doing a check when a user inputs an email to see if the email exists or not. $('form.recover-form#check-form').on('submit', function(e){ var form = $(this), input = $('.check-recover-email'), span = $('.recover-error'), email = input.val(); span.text(''); e.preventDefault(); $.ajax({ url: 'ajax/check-email', async: 'false', cache: 'false', type: 'POST', data: {email: email}, success: function(response) { if ( response == 'no' ) { span.text('email does not exist'); } else if (

preventDefault() not working on SELECT elements in Firefox 9.0.1

怎甘沉沦 提交于 2019-12-10 12:37:06
问题 I realise there are other questions on preventDefault() not working with Firefox, but they did not help me. I've got three SELECT lists, and all I want is to navigate between them using the arrow keys without changing any values . The code works great in Chrome, but in Firefox it moves focus and then changes the value on the element just moved to. http://jsbin.com/ofitif/3/edit JavaScript: $(document).ready(function () { $('.myinput').keydown(function (evt) { onkeydown(evt); }); $('.myinput

preventDefault doesn't work [duplicate]

妖精的绣舞 提交于 2019-12-10 12:13:01
问题 This question already has answers here : JS & jQuery can't detect html elements, and say's they are undefined (4 answers) Closed 4 years ago . I have a problem with preventDefault function. It doesn't work. Here is my JS file: (function() { var app = { initialize : function () { this.setUpListeners(); }, setUpListeners: function () { $('form').on('submit', app.submitForm); }, submitForm: function(e){ e.preventDefault(); } } app.initialize(); }()); My HTML code has 2 confirm button. Second

Prevent browser pop on taphold event

不问归期 提交于 2019-12-10 02:43:38
问题 In a jquery-mobile based web app, how do i prevent the default browser menu from showing on "tap hold" .. instead i want to show a custom dialog page .. mentioned below is my code as of now .. $(".task_row").bind('taphold',function(event, ui){ event.preventDefault(); $("#slide_down_menu").trigger('click'); }); 回答1: use css: a { -webkit-touch-callout: none !important; } to not show the standard dialog 回答2: The trouble is that the 'taphold' event that you are binding to is a custom event that

I'm having trouble using the event.preventDefault(); for an ahref on my DOM

為{幸葍}努か 提交于 2019-12-09 06:15:54
问题 I'm having trouble using the event.preventDefault(); for an ahref on my DOM. How do you prevent the url from posting a nofollow delete, as specified by the HTML using JQuery? <td class="trash_can"> <a rel="nofollow" data-remote="true" data-method="delete" data-confirm="Are you sure you want to delete Greek Theater at U.C. Berkeley?" href="/promotions/2/places/46"> <img id="trash_can" src="http://test.dev/images/trash.png?1305741883" alt="Trash"> The following code should subvert the HTML but

How to put a callback in the submit event listener of a form to wait for user's response to jquery impromptu's prompt?

孤街浪徒 提交于 2019-12-07 22:34:15
问题 Here is what I want to do - Display a prompt (using jquery's impromptu) when user clicks on submit button of the main form. The prompt is again a form which has a password field and an Ok and Cancel button. The main form (along with the password value, appended to the main form) is posted when User clicks on Ok. The form is not submitted if user clicks on Cancel. Details I asked a question earlier - jquery form submit() not working inside callback function after preventing normal submit while

sweetAlert preventDefault and return true

﹥>﹥吖頭↗ 提交于 2019-12-07 11:52:11
问题 I tried sweeAlert plugin, which works perfectly, but I cant figure out how to do default stuff after confirm. $(document).ready(function () { function handleDelete(e){ e.preventDefault(); swal({ title: "Are you sure?", text: "You will not be able to recover the delaer again!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "Yes, delete!", closeOnConfirm: false }, function (isConfirm) { if (isConfirm) { return true; } }); }; }); and the button <a

React - how to trigger preventDefault() before the synthetic event is recycled?

好久不见. 提交于 2019-12-07 11:14:42
问题 I have the following function within a React component which is run when a link is clicked: onClick(e, { name }) { e.stopPropagation(); const doIt = await checkSomething(); if (doIt) { e.preventDefault(); doSomethingElse(); } } Problem is that by the time e.preventDefault() is reached the synthetic event is recycled. So, how do I tell the browser not to follow the link if it is clicked, when some logic is needed to calculate this decision and before the synthetic event is recycled? 回答1: One

undo preventDefault() or better way to programmatically disable collections of links

假如想象 提交于 2019-12-07 05:17:35
问题 I have a page that has event listeners for the network status. When the network is 'offline' I want to disable any cross domain links as to go into an offline mode. I was trying to use .preventDefault() , however when the app comes back online I need to re-enable the links. Event Listeners //check network status if(!navigator.onLine) { offlineLinks(); //Offline mode function } //add event listeners for network status window.addEventListener('offline', function(e) { offlineLinks(); //Offline