可以在UIWebView中打开弹出链接吗? [英] Opening popup links in UIWebView, possible?

查看:126
本文介绍了可以在UIWebView中打开弹出链接吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIWebView,我在我的应用程序中使用它作为嵌入式浏览器。



我注意到打开新窗口的网页中的链接被忽略而没有任何对我代码的调用。



我已经尝试过破解

   - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)请求navigationType:(UIWebViewNavigationType)navigationType 

然后选择一个可以打开弹出窗口的链接,并且永远不会遇到断点。
我有什么办法可以拦截弹出链接的选择并获取URL并正常加载吗?



我对显示不感兴趣应用程序本身的一个弹出窗口,我只想在弹出窗口中加载的URL加载到主webview本身。



这是否可能?



谢谢!

解决方案

我也碰到了这个,和HTML重写是我能想到的最佳解决方案。我遇到的最大问题是,在调用webViewDidFinishLoad:方法之前,Web浏览器是交互式的,持续几秒钟,因此链接似乎会被破坏几秒钟,直到它们被重写为止。 / p>

我重写了三个方面:链接,表单帖子和对window.open()的调用。



我使用了与 Jasarian's 通过迭代标签和表单来覆盖链接和表单的目标。要覆盖window.open,我使用了类似于以下内容的代码:

  var oldWindowOpen = window.open; 
window.open = function(url,sName,sFeatures,bReplace){
oldWindowOpen(url,'_ self');
};


I have a UIWebView which I'm using as an embedded browser within my app.

I've noticed that links in webpages that open new windows are ignored without any call into my code.

I've tried breakpointing on

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

and then selecting a link that would open a popup window, and the breakpoint is never hit. Is there anything I can do to intercept that selection of the popup link and get the URL and just load it normally?

I'm not interested in displaying a popup window in the app itself, I just want the URL of whatever is going to be loaded in the popup window to load in the main webview itself.

Is this possible?

Thanks!

解决方案

I ran into this as well, and HTML rewriting was the best solution I could come up with. The biggest issue that I ran into with that approach is that the web browser is interactive for up to a couple of seconds until the webViewDidFinishLoad: method is called, so the links seem to be broken for a few seconds until they're rewritten.

There's three areas that I rewrote: links, form posts, and calls to window.open().

I used a similar approach to the first code snipped in Jasarian's answer to overwrite the target for links and forms by iterating over tags and forms. To override window.open, I used code similar to the following:

var oldWindowOpen = window.open;
window.open = function(url, sName, sFeatures, bReplace) {
  oldWindowOpen(url, '_self');
};

这篇关于可以在UIWebView中打开弹出链接吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆