<p dir="auto">Hi,<br>
I looked into the following sentence in <strong>will-navigate</strong> event (<a href="https://github.com/atom/electron/blob/master/docs/api/web-view-tag.md">https://github.com/atom/electron/blob/master/docs/api/web-view-tag.md</a>) documentation.</p>
<blockquote>
<p dir="auto">Calling event.preventDefault() does NOT have any effect.</p>
</blockquote>
<p dir="auto">So how can we prevent webview from navigating to other page? I intent to launch default browser when user clicks on a URL link on webview.<br>
Here is my code on the renderer process.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content=" webview.addEventListener('will-navigate', function(e) {
        e.preventDefault();
        require('electron').shell.openExternal(e.url);
 });"><pre class="notranslate"> <span class="pl-s1">webview</span><span class="pl-kos">.</span><span class="pl-en">addEventListener</span><span class="pl-kos">(</span><span class="pl-s">'will-navigate'</span><span class="pl-kos">,</span> <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">e</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-s1">e</span><span class="pl-kos">.</span><span class="pl-en">preventDefault</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'electron'</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">shell</span><span class="pl-kos">.</span><span class="pl-en">openExternal</span><span class="pl-kos">(</span><span class="pl-s1">e</span><span class="pl-kos">.</span><span class="pl-c1">url</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
 <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">With this code, when I click the URL link on webview, webview will navigate to the new page and default browser also opened showing the new page. I want webview to stop navigating to the new page.</p>
<p dir="auto">It would be very useful to get events related to navigation:</p>
<ul dir="auto">
<li><code class="notranslate">will-navigate</code>: when the webview is about to navigate (url have been changed but no requests have been emited yet). It could eventually be cancelled with <code class="notranslate">event.preventDefault()</code>)</li>
<li><code class="notranslate">page-url-set</code>: like <code class="notranslate">page-title-set</code> but for url. It is different than <code class="notranslate">before-navigate</code> because it should also handle anchor changes and HTML5 url set without navigating (with <code class="notranslate">history.pushState</code> and <code class="notranslate">history.replaceState</code>)</li>
<li><code class="notranslate">did-navigate</code>: after the navigation has occured (i.e. when a new entry have been pushed to history and canGoBack/canGoForward/canGo... may have changed)</li>
</ul>