Detect window.open () from UIWebView

Short question: is it possible to detect window.open() in a UIWebView using a UIWebViewDelegate or is there any other way to achieve this? I need a url when window.open() -Event is fired to show a UIAlertView .

+6
source share
2 answers

You need to overwrite window.open() with JavaScript:

 [webView stringByEvaluatingJavaScriptFromString:@"window.open = function (open) { return function (url, name, features) { window.location.href = url; return window; }; } (window.open);"]; 
+11
source

Try using these delegate methods. Hope this helps.

 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType; - (void)webViewDidStartLoad:(UIWebView *)webView; 
0
source

Source: https://habr.com/ru/post/917423/


All Articles