The problem is solved by itself ...
FYI . Apparently, the error was Mac OS or Chromium, because after the last problem with the system and browser they disappeared as suddenly as before. It looks like not related to jQuery or JavaScript API.
I will keep this question for several days, and I will delete it later, since it does not comply with the StackOverflow rules in this situation.
Original post:
I have a simple JS confirmation inside a click listener, just like in the code below, more requests (i.e. AJAX, no JS duplicates, etc.).
The problem is that in some browsers (for example, Chrome and Opera on Mac OS) the confirmation dialog is activated twice , and my question is: did I miss something obvious or is it a significant error of the mentioned browsers? Is there any workaround to help me prevent this? Also tried with e.preventDefault();also no luck.
Edit I should also mention that if there is no confirm('...');click inside, it starts only once (so only one of them will be checked ... in the console). With confirmation, both logs appear twice in the console, but boolean is in the opposite order - for the sample - if I click Cancelfirst and OKlater the console logs truefirst and falseat the end ... quite strange: S
Versions:
- jQuery: 1.11.3 - 1.12.0
- Chrome: 47.0.x ()
- Opera: 34.0. * ()
():
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test...</title>
<script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>
</head>
<body>
<div class="myBtn" data-field="one">Take one</div>
<div class="myBtn" data-field="two">Take two</div>
<div class="myBtn" data-field="three">Take three</div>
<div class="myBtn" data-field="four">Take four</div>
<script>
$(document).ready(function () {
$(document).on('click', '.myBtn', function () {
console.log('Let us check...');
var confirmation = confirm('Are you sure you want ' + $(this).data('field') + '?');
console.log(confirmation);
});
});
</script>
</body>
</html>
: https://jsfiddle.net/gu58wwtg/1/
: , ( JS, jQuery), prompt('...'); ( ) confirm('...'); , , , , , , . , ;)