简体   繁体   English

如何防止野生动物园弹出密码保存框?

[英]How to prevent safari from popping up a password saving box?

I'm confused by safari saving password box for few days: that is how to disable it popping up when submitting the form because I don't want to save the username and password. 野生动物园保存密码框几天让我感到困惑:这是如何在提交表单时禁止其弹出,因为我不想保存用户名和密码。

Obviously, the "password" will trigger the saving mechanism。 显然,“密码”将触发保存机制。

 <input type="test" name="username"> <input type="password" name="password"> 


But I change the "password" type to "text" type and use a property of css: -webkit-text-security which works for chrome rather than safari. 但是我将“ password”类型更改为“ text”类型,并使用css的属性:-webkit-text-security,它适用于chrome而不是safari。

The -webkit-text-security can also inform the safari the element is a password input. -webkit-text-security也可以通知safari元素是密码输入。

The following code using Vue framework and element-ui. 以下代码使用Vue框架和element-ui。 The 'el-input' component has "off" value for "autocomplete" property default. “ el-input”组件的“ autocomplete”属性默认值为“ off”。

I post the data by axios rather than submit the form. 我通过axios发布数据,而不是提交表单。

 ...methods: { submit() { const data = { accountName: this.form.accountName, password: this.form.password } axios.post(url, data) } } 
 .password { -webkit-text-security: disc; } 
 <el-form ref="form" label-position="right" :model="form"> <el-form-item label="账号名" prop="accountName"> <el-input v-model="form.accountName" :disabled="isEdit"></el-input> </el-form-item> <el-form-item label="登陆密码" prop="password" required> <el-input class="password" type="text" ref="pwd1" v-model="form.password"></el-input> </el-form-item> </el-form> <el-button class="submit-btn" type="primary" size="medium" @click="submit">create</el-button> 


So, is there any other simple and effective ways to address it? 那么,还有其他简单有效的方法来解决它吗?

Hope your reply! 希望您的答复!

Thanks very much! 非常感谢!

Best, Cassie 最好的,卡西

The short answer is that you cannot. 简短的答案是你不能。 This is because this depends on the browser and the user's configuration. 这是因为这取决于浏览器和用户的配置。

The long answer is that to prevent it from happening you can try some things: there is an option called autocomplete ; 长答案是防止发生这种情况,您可以尝试一些方法:有一个名为autocomplete的选项; this is used by some browsers to let the developer tell the browser that the user must not have any "help" during a form completion. 一些浏览器使用它来让开发人员告知浏览器,用户在填写表单期间不得获得任何“帮助”。 If you set it to false some browsers will not save a password related to the form. 如果将其设置为false,则某些浏览器将不会保存与表单相关的密码。 However in some browsers, the user can still click on the key icon and select save password manually. 但是,在某些浏览器中,用户仍然可以单击键图标并手动选择“保存密码”。

<form action="myPage" method="post" autocomplete="off">

The way I would use is yo emulate what the browser does, I mean to not submit the form but instead make an AJAX request with the login and then redirect the user to the page required once the login is succesful. 我使用的方式是模拟浏览器的功能,我的意思是不提交表单,而是使用登录名提出AJAX请求,然后在登录成功后将用户重定向到所需的页面。

For example, lets suppose that you had <form method="POST" action="myPage"> then you would eliminate the form, you would replace the <input type="submit" value="accept" /> with a <button id="whatever">accept</button> and then, in you JS file would put something like: 例如,假设您有<form method="POST" action="myPage">然后您将消除该表单,将<input type="submit" value="accept" />替换为<button id="whatever">accept</button> ,然后在您的JS文件中添加类似以下内容:

$("#whatever").click(function (evento) {
    jQuery.ajax({
        url: "myPage",
        dataType: "json",
        method: "POST",
        data: {
            user: $("#userField").val(),
            pw: $("#pwField").val()
        },
        success: function (result) {
            if (result.success) {
                window.location.href = "myPageAfterLogin";
            } else {
                // what should happen if the loggin failed
            }
        }
    });
});

and in your page you have to change so, when the login success, instead of redirecting the user to "myPageAfterLogin", you must return a JSON with a success mark, like 并且必须在页面中进行更改,以便在登录成功后,必须返回带有成功标记的JSON,而不是将用户重定向到“ myPageAfterLogin”

$result['success'] = true;
exit(json_encode($result));

I stay attend to any question. 我会继续处理任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM