Gwt 在FireFox 中 不能记住密码

参考:http://raibledesigns.com/rd/entry/browser_based_username_password_autocomplete

 

1、页面设置一个隐藏表单,action 设置为 javascript:void(0);"

 <form method="post" action="javascript:void(0);" style="display:none ">
    <input type="text" id="j_username" name="j_username" value=""/>
    <input type="password" id="j_password" name="j_password" value=""/>
    <input type="submit" value="Login" id="loginBtn"/>
</form>

2、真正要提交的表单元素 设置为 autocomplete=off

    DOM.setElementAttribute(edt_username.getElement(), "autocomplete", "off");
    DOM.setElementAttribute(edt_password.getElement(), "autocomplete", "off"); 

3、表单提交前,用隐藏表单记录表单值,并调用隐藏表单的提交

/**
   * invoke before actual form submit
   */
  public  void toFixFFAutocomplete(){
     DOM.getElementById("j_username").setAttribute("value",edt_username.getValue());
  DOM.getElementById("j_password").setAttribute("value", edt_password.getValue());
  clickVirtualFormLogin();
  }

  public static native void clickVirtualFormLogin() /*-{
   // alert("page");
  $doc.getElementById("loginBtn").click();
  }-*/;

 

4、页面初始化时,从隐藏表单获取值,填入真正的表单中

private void setFFAutocomplete() {
 // delay 500 ms to set username&password
    Timer t = new Timer() {
     public void run() {
      edt_username.setValue(getElementValue("j_username"));
      edt_password.setValue(getElementValue("j_password"));
        if (edt_password.getValue() != null&&edt_password.getValue().trim().length()>0) {
       edt_password.setFocus(true);
          }else{
          edt_username.setFocus(true);
          }
     }
      };  
      
      t.schedule(500);//注意要延时 0.5秒
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值