简体   繁体   English

启用用户互动的Javascript

[英]User Interaction Enabled Javascript

I am writing a Javascript application and am going to wrap it in a native iOS application. 我正在编写一个Javascript应用程序,并将其包装在本机iOS应用程序中。 I would like to block user interaction on the UIWebView containing the JS app for a second or two following an event. 我想在事件发生后一两秒钟内阻止包含JS应用程序的UIWebView上的用户交互。

Normally I would use the self.webView.userinteractionenabled = NO but the event is triggered in Javascript. 通常我会使用self.webView.userinteractionenabled = NO,但是该事件是在Javascript中触发的。 How can I block the user from interacting with the web view? 如何阻止用户与Web视图进行交互?

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: 当事件在Javascript代码中发生时,您可以使用以下方法将消息发送到本机包装:

Set up the following UIWebViewDelegate method (don't forget to set the delegate for the UIWebView): 设置以下UIWebViewDelegate方法(不要忘记为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: 现在,当您的事件发生时,请从JavaScript代码中调用委托方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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