title: How do I gracefully interrupt loading of a certain URL in Cordova's InAppBrowser and open it in the system browser?
body: <p>I am using Cordova's inappbrowser plugin to display web parts in my app. On the website, there are sharing links, e.g. for WhatsApp:</p>
  
  <pre><code>&lt;a href="whatsapp://send?text=Check this out"&gt;Share on WhatsApp&lt;/a&gt;
  </code></pre>
  
  <p>Now when clicking these links in inappbrowser, it simply tries to load <code>whatsapp://send?...</code> as a URL and displays an error page. </p>
  
  <p>What I want to do instead is open links that start with <code>whatsapp://</code> using the given system's browser/URI handler so it resembles the behavior when clicking such link in the system's browser. To do that, I did the following:</p>
  
  <pre><code>urlChanged = function(event) {
      // when a "whatsapp://" link is clicked, open it in the system browser
      if(event.url.startsWith("whatsapp://")) {
          window.open(event.url, "_system");
          return;
      } 
  }
  // Add an "loadstart" event listener to the inappbrowser:    
  browser.addEventListener("loadstart", urlChanged);
  </code></pre>
  
  <p>So far, this somewhat works, but with quirks: </p>
  
  <ol>
  <li>While the event immediately fires when the user clicks a WhatsApp link (checked that by firing an alert), it takes like two or three seconds for the system browser to actually open. </li>
  <li>While waiting these 2-3 seconds and when returning to the app, the user sees an inappbrowser error page that the <code>whatsapp://</code> link could not be opened ("unknown url scheme").</li>
  </ol>
  
  <p>To mitigate point 2, I also tried the following in the event listener, without success (the behavior is exactly the same):</p>
  
  <pre><code>urlChanged = function(event) {
      if(event.url.startsWith("whatsapp://")) {
          // stop loading the whatsapp:// link in inappbrowser
          browser.stop(); 
          // go back in history to display page where whatsapp:// link was on
          browser.history.back(); 
          window.open(event.url, "_system");
          return;
      } 
  }
  browser.addEventListener("loadstart", urlChanged);
  </code></pre>
  
  <p>Can you guide me how to solve points 1 and 2?</p>