开发者

Force Safari form AutoFill entry when using JavaScript to prevent the form's submit

开发者 https://www.devze.com 2022-12-13 03:52 出处:网络
I want Safari\'s form AutoFill feature to work on the forms in my web app. All of our form\'s submit events are prevented and instead we send data to开发者_开发技巧 the server via XHR (Ajax) POST.

I want Safari's form AutoFill feature to work on the forms in my web app. All of our form's submit events are prevented and instead we send data to开发者_开发技巧 the server via XHR (Ajax) POST.

The problem is, Safari's default for creating a new entry in it's AutoFill (autocomplete) "database" requires the form's submit event to fire and bubble all the way up. From my testing this is what I concluded and works for form GET and POST methods.

This issue is not present in Firefox; all of our forms retain the previous values that were "submitted" for each field. This is the desired behavior we want in Safari.

In our app a user will fill in the same form multiple times over multiple sessions. In some cases it would be useful for the browser to autocomplete (AutoFill in Safari's case) these fields for the user based on their previously submitted values.

I was wondering if anyone else has ran into this issue with Safari? And better yet if they have a solution (even if Safari-specific) to tell (or force) Safari to save form-field values into it's AutoFill database even if the form's submit event is prevented?

I've tried preventDefault() higher-up in the DOM, letting the submit event bubble-up to the form's parent DOM node; no difference in behavior. It's possible this is just a bug in Safari…


For a form that uses HTTPS, this is the expected behaviour for Safari, which is against he W3C standards.

The only way around this is to include an image, or similar tag, that points to a HTTP resource. Of course, you will lose your padlock and your page will be viewed as insecure.

0

精彩评论

暂无评论...
验证码 换一张
取 消