Ios 如何在UIWebView上获取javascript警报消息的内容?
我一直试图在UIWebView上获得一条“javascript警报”消息。 虽然可以通过“onJsAlert”事件在Android WebView上获得一个, UIWebView并没有一种方法。。。Ios 如何在UIWebView上获取javascript警报消息的内容?,ios,uiwebview,Ios,Uiwebview,我一直试图在UIWebView上获得一条“javascript警报”消息。 虽然可以通过“onJsAlert”事件在Android WebView上获得一个, UIWebView并没有一种方法。。。 如果有人知道怎么做,请告诉我。你不能用简单的方法(ASAIK)来做。 让我们干掉它! 尝试重新定义您的警报功能,记住在中传递js警报的警报消息 我是用于检测的特殊URL 并在警报url中获取所需内容: - (BOOL) webView:(UIWebView *)webView shouldStart
如果有人知道怎么做,请告诉我。你不能用简单的方法(ASAIK)来做。 让我们干掉它! 尝试重新定义您的警报功能,记住在中传递js警报的警报消息 我是用于检测的特殊URL 并在警报url中获取所需内容:
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL* url = request.URL;
// look for our custom action to come through:
if ( [url.host isEqualToString: @"I AM A SPECIAL URL FOR detecting"] )
{
// parsing the url and get the message, assume there is a '='for value, if you are passing multiple value, you might need to do more
NSString* message = [[[[url query] componentsSeparatedByString: @"="] lastObject] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// show our alert
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle: @"My Custom Title"
message: message
delegate: nil
cancelButtonTitle: @"OK"
otherButtonTitles: nil];
[alertView show];
return NO;
}
return YES;
}
你不能用简单的方法(ASAIK)来做。 让我们干掉它! 尝试重新定义您的警报功能,记住在中传递js警报的警报消息 我是用于检测的特殊URL 并在警报url中获取所需内容:
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL* url = request.URL;
// look for our custom action to come through:
if ( [url.host isEqualToString: @"I AM A SPECIAL URL FOR detecting"] )
{
// parsing the url and get the message, assume there is a '='for value, if you are passing multiple value, you might need to do more
NSString* message = [[[[url query] componentsSeparatedByString: @"="] lastObject] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// show our alert
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle: @"My Custom Title"
message: message
delegate: nil
cancelButtonTitle: @"OK"
otherButtonTitles: nil];
[alertView show];
return NO;
}
return YES;
}
请尝试提供更多详细信息-您尝试过什么以及如何知道它不起作用?请尝试提供更多详细信息-您尝试过什么以及如何知道它不起作用?我认为您的解决方案很有趣!我忘了在哪里找到的。它在我的dropbox中存在了很长一段时间,我认为最好的解决方案就在这里。看看这一类,不是真的,也许在StackOverflow的某个地方,我认为你的解决方案很有趣!我忘了在哪里找到的。它在我的dropbox中存在了很长一段时间,我认为最好的解决方案就在这里。看看这一类,不太可能,可能在stackoverflow的某个地方