Mahmoud Adam
Mahmoud Adam

Reputation: 5852

OSX - Disable External Site Linking for Webview

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">

Upvotes: 2

Views: 245

Answers (1)

Rob Napier
Rob Napier

Reputation: 299355

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

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].

Upvotes: 2

Related Questions