我想跳過一個網站的登錄頁面,這樣我就可以給用戶帶來更加美觀的登錄頁面,並保存它們的登錄憑證在自動登錄未來。到目前爲止,我有兩個UITextFields和一個UIButton。用戶輸入他們的用戶名和密碼,當按下UIButton時,他們的詳細信息將被輸入到網站登錄頁面上的實際網絡表單中,隨後的「登錄」頁面將顯示在UIWebView中。當應用程序記錄用戶時,webView將被隱藏,然後在加載「登錄」頁面時顯示。呼叫在一個UIWebView的HTML web表單「動作」
我已經設法填充webform,但根本無法實際提交它!我確定有一個非常簡單的解決方案!
這是我到目前爲止的代碼,如果有一個更好的辦法我應該做這讓我知道!
-(IBAction)login:(id)sender
{
// Create js strings
NSString *loadUsernameJS = [NSString stringWithFormat:@"var username = document.getElementsByName('username')[0]; username.value='%@';", username.text];
NSString *loadPasswordJS = [NSString stringWithFormat:@"var password = document.getElementsByName('password')[0]; password.value='%@';", password.text];
// Autofill the form - this works, and I can see the values being put into the webform
[self.webView stringByEvaluatingJavaScriptFromString: loadUsernameJS];
[self.webView stringByEvaluatingJavaScriptFromString: loadPasswordJS];
// This is the method I have tried to submit the form, but nothing happens (ct100 is the ID of the form).
[self.webView stringByEvaluatingJavaScriptFromString:@"document.ct100.submit();"];
}
感謝您的回覆Sanjit,遺憾的是仍然沒有運氣!我不知道爲什麼這不起作用。 – Luke
你在你的UIWebViewDelegate實現中實現了webView:shouldStartLoadWithRequest:navigationType:您需要爲指定的請求返回YES才能使Web視圖導航到提交網址。 –
我對這個有點新,你想介紹一下更詳細的介紹,我會如何處理具體的請求? – Luke