我在 UIWebView 中显示一个网站页面,其中有一个下拉菜单。用户能够从下拉列表中选择值,但是当应用程序关闭并再次打开时,此下拉列表停止工作意味着用户无法选择它。
奇怪的是,如果我们在那个 dropdwon 上显示 javascript onclick 的警告框,那么在点击警告框的 ok 按钮后一切正常(意味着 dropdwon 变得可点击),那么它的原因和解决方案是什么?
最佳答案
我遇到了同样的问题,所以我找到了解决方法 在您的网站中,将以下 javascript 行放在 document.ready 中,其中存在下拉列表
var appname = 'yourappName';
var actionName = 'displayAlert';
var url = appname + '://' + actionName;
document.location.href = url;
在你有 UIWebView 的 Controller 中放置以下代码
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
// these need to match the values defined in your JavaScript
NSString *myAppScheme = @"wfsapp";
NSString *myActionType = @"displayAlert";
// ignore legit webview requests so they load normally
if (![request.URL.scheme isEqualToString:myAppScheme]) {
return YES;
}
// get the action from the path
NSString *actionType = request.URL.host;
// look at the actionType and do whatever you want here
if ([actionType isEqualToString:myActionType]) {
/* UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Loading"
message:@"Initialising Search Filters..."
delegate:self
cancelButtonTitle:NULL
otherButtonTitles:nil];*/
//[alert show];
/* UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@""
message:NULL
preferredStyle:UIAlertControllerStyleActionSheet];
alertController.view.hidden = YES;
alertController.modalPresentationStyle = UIModalPresentationCurrentContext;
alertController.view.backgroundColor = [UIColor clearColor];*/
UIViewController *alertController = [UIViewController alloc];
alertController.view.hidden = YES;
alertController.view.backgroundColor = [UIColor clearColor];
self.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:alertController animated:NO completion:^ {
}];
[alertController dismissViewControllerAnimated:NO completion:nil];
}
当您的页面加载并执行 javascript 行时,上面的代码不会显示任何 View Controller ,但会触发下拉列表再次工作
关于html - 无法在 IOS 9 的 UIWebView 中选择下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39272945/