我的应用程序有以下代码。
- (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 中看到任何错误,请告诉我,