OSX - 禁用Webview的外部站点链接 [英] OSX - Disable External Site Linking for Webview
问题描述
我正在查看WebView中的本地html页面,如果用户点击页面中的任何按钮即< a href =www,我想禁用去任何外部网站。 google.com> c>
I'm working to view a local html page inside a WebView and I want to disable going to any external website if the user clicks any button within the page i.e. <a href="www.google.com">
推荐答案
您要设置 policyDelegate
为您的视图。请参阅 WebPolicyDelegate
的文档。您要实现的具体方法是:
You want to set a policyDelegate
for your view. See the docs for WebPolicyDelegate
. The specific method you want to implement is:
- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request
frame:(WebFrame *)frame
decisionListener:(id<WebPolicyDecisionListener>)listener
最简单的事情就是调用 [listener ignore]
。这也将防止任何后退/前进导航,重新加载或表单提交工作。如果你想要更多的控制,你可以看看 actionInformation
字典,并检查类型之前调用 [listener ignore]
[listener use]
。
The simplest thing to do is just call [listener ignore]
for everything. That will also prevent any back/forward navigation, reloads, or form submits from working. If you want more control, you can look at the actionInformation
dictionary and check the type before calling [listener ignore]
or [listener use]
.
这篇关于OSX - 禁用Webview的外部站点链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!