2012年4月30日 星期一

[iOS]取得 WebView Element 和 Save Password

當我們程式會存取WebView登入畫面時 可以透過下面的JavaScript語法賦與帳號和密碼 已達成Auto fill的功能
NSString *usernameJS = [NSString stringWithFormat:@"document.getElementById('account').value ='%@'", username];
NSString *passwordJS = [NSString stringWithFormat:@"document.getElementById('password').value ='%@'", password];
[self.logInWebView stringByEvaluatingJavaScriptFromString: usernameJS];
[self.logInWebView stringByEvaluatingJavaScriptFromString: passwordJS];

如果要取值的話只要執行@"document.getElementById('account').value" 就可以囉

另外密碼除存在本機端可透過 SFHFKeychainUtils 這程式去做密碼的控管與保護 
詳情細節請參考  
http://stackoverflow.com/questions/4772341/is-it-possible-for-a-uiwebview-to-save-and-autofill-previously-entered-form-valu

沒有留言:

張貼留言