在 Cocoa Touch Webview 开始加载之前验证用户触摸的链接
有一位潜在客户问我是否可以阻止用户在 iPad 应用程序中离开他们的网站?因此,我需要在网络视图中加载客户端站点,并以某种方式禁用无效链接,即横幅和促销链接。
我想知道是否有一种方法可以在加载之前捕获视图中已触摸的链接。
如果没有办法做到这一点,是否可以在将网页加载到网络视图之前去除无效链接?
I had a potential client ask me if I can prevent a user navigating away from their website within an iPad app? So I would need to load the client site within a web view and somehow disable invalid links i.e. banners and promotional links.
I am wondering if there is a way to catch the link that has been touched within the view before it is loaded.
If there is no way to do this, is there away to strip a web page of invalid links before it is loaded into the web view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
UIWebViewDelegate
方法webView:shouldStartLoadWithRequest:navigationType:
。当用户点击链接时调用它。如果您不想处理任何链接,则返回NO
;如果您希望 Web 视图处理请求,则返回YES
。更多信息请参阅 Apple 文档。一件好事是过滤掉一些请求并根据请求的 URL 方案或基于
UIWebViewNavigationType
值自行处理它们。注意:对于您处理的过滤请求,您仍然返回NO
。Use
UIWebViewDelegate
methodwebView:shouldStartLoadWithRequest:navigationType:
. It's called when user taps a link. ReturnNO
if you don't want to handle any links orYES
if you want your web view to handle the request. More info in Apple docs.A nice thing is to filter out some requests and handle them yourself based on e.g. URL-scheme of the request or based on
UIWebViewNavigationType
value. Note: for a filtered requests that you handle, you still returnNO
.