简体   繁体   中英

User Interaction Enabled Javascript

I am writing a Javascript application and am going to wrap it in a native iOS application. I would like to block user interaction on the UIWebView containing the JS app for a second or two following an event.

Normally I would use the self.webView.userinteractionenabled = NO but the event is triggered in Javascript. How can I block the user from interacting with the web view?

Guessing return false on a touch event of some sort? It's scrolling that I want to block.

Thanks!

When the event occurs in your Javascript code you can send a message to the native wrapper by using the following method:

Set up the following UIWebViewDelegate method (don't forget to set the delegate for the UIWebView):

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
   NSURL *url = [request URL];
   if ([[url scheme] isEqualToString:@"block"]) {
      // do the your blocking code here
      return NO;
   }

   return YES;
}

Now when your event happens, call the delegate method from your javascript code:

window.location.href = "block://";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM