Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I came across the same problem and the solution I have found is not too intuitive.</p> <p>As a previous answer indicated, you have to use the <code>WebPolicyDelegate</code> protocol, defined in <code>&lt;WebKit/WebPolicyDelegate.h&gt;</code>. It is an informal protocol, so you cannot write <code>@interface MyDelegate : NSObject &lt;WebPolicyDelegate&gt;</code>.</p> <p><code>#import &lt;WebKit/WebPolicyDelegate.h&gt;</code> (or the whole WebKit.h) and implement the <code>webView:decidePolicyForNavigationAction:request:frame:decisionListener:</code> method as follows:</p> <pre><code>- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id &lt;WebPolicyDecisionListener&gt;)listener { if ([actionInformation objectForKey:WebActionElementKey]) { [listener ignore]; [[NSWorkspace sharedWorkspace] openURL:[request URL]]; } else { [listener use]; } } </code></pre> <p>Then set your class as PolicyDelegate for the WebView.</p> <p>Logic dictates you should use a different key from the <code>actionInformation</code> dictionary, namely <code>WebActionNavigationTypeKey</code>, whose value <em>should</em> be an enum that can include <code>WebNavigationTypeLinkClicked</code>. Unfortunately, the values I have seen look random and far beyond the correct range (6 decimal digits integers while the enum goes from 0 to 5).</p> <p>But, there is something else to check, the <code>WebActionElementKey</code>, that returns the HTML entity that originates the navigation action. When loading data in the frame from code, its value is <code>nil</code> whereas when user clicks a link, its value is the (parsed) <code>&lt;a&gt;</code> entity. Checking it for non-<code>nil</code> value does the trick.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload