我對我的應用程序有以下代碼。iOS獲取過去的登錄表單。
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//Set the values
NSString* firstValue = @"guest";
NSString* secondValue = @"guest";
// write javascript code in a string
NSString* javaScriptString = @"document.getElementById('Login1_UserName').value=%@;"
"document.getElementById('Login1_Password').value=%@;"
"document.forms['form1'].submit();";
// insert string values into javascript
javaScriptString = [NSString stringWithFormat: javaScriptString, firstValue, secondValue];
// run javascript in webview:
[webView stringByEvaluatingJavaScriptFromString: javaScriptString];
}
- (void)launchWebPageWithOptions
{
NSString *urlString = @"http://demo.leadtools.com/MedicalViewer/default.aspx";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *requestObject = [NSURLRequest requestWithURL:url];
[iOSWebView loadRequest:requestObject];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self launchWebPageWithOptions];
}
出於某種原因,我無法執行使用javascript調用的自動登錄。我不是JS專家,所以,如果你能看到我javaScriptString任何錯誤,請讓我知道,
是'「'開頭和JS或 – Charlie
的Objective-C的對象 - 的一部分的線路部分的末端的內部@?」。」是JavaScript –
您是否通過JSHint運行JS? – Charlie