We had the same problem recently. On top of that, we had a AJAX validation of our form happening onBlur. For some strange reason, this would trigger safari to autofill our email input field again. So every time you fill in the email that you want, Safari would fill in an email that it preferred instead. Making it impossible to go through our form.
Our solution
was to pretty much break Safaris (and Chromes) autofill algorithm.
HTML:
<div class="douchebag_safari">
<input class="js-clear_field" tabindex="-1" name="e-mail" type="email">
<input class="js-clear_field" tabindex="-1" name="Ecom_User_Password" type="password">
</div>
CSS:
.douchebag_safari {
position: fixed;
width: 1px;
left: -50px;
}
.douchebag_safari input {
width: 1%;
}
JS:
$('#form').on('submit', function () {
"use strict";
$('.js-clear_field').attr('disabled', 'disabled');
}
The jist of it is: We put input fields of type email and password with names that will rank higher (or same?) in Safaris autofill algorithm and hide them outside the screen. OnSubmit, the fields will be disabled and will thus be excluded from the POST to our backend.
The downside is that users won't have autocomplete on our form, but we decided that it was worth it in our case.
NOTE (assuming you care): Users with Javascript disabled will still get these fields included in their POSTs. Depending on your setup, you will need to allow these two fields to come through to your backend to prevent errors. Just make sure you don't do anything with these fields for security reasons!
As a bonus, this solved a bug where Chrome (35) assumed the input field above the password field is the username. In our case, it was a number field, giving strange user experience and bugs.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…