Did You Know?

JOOJ -Best Web Clone, Software & Mobile App Development Company

URL Handling API

Author: admin 153 views

It often makes sense in WebView based apps to treat different web addresses differently. If you place a social media button in your web app, a click on it should probably not open the social media page in your app, but in the right app (e.g., the system browser). It’s good that WebViewGold has all the features to enable powerful configuration and treat links the way you want it.


Option 1: Open all external hosts in System Browser

If you want to open every URL, which is not on your host in System Browser, please set OPEN_EXTERNAL_URLS_IN_ANOTHER_BROWSER (in Config.java file) to true.



Option 2: Open only specific hosts in System Browser

Please search for this snippet (CMD+F) in MainActivity.java:

Open a specific URL in the system browser instead of WebView

To add another domain, just copy this snippet and insert another host, which should be opened in System Browser. Please enter the host precisely the way you link to it.

URL Handling – Open links in a tab/additional In-App-Browser

There are some cases for links that do not feel to be “important enough” to open them in the System browser externally but “too specific” for opening them in the app WebView itself (e.g., your Terms and Conditions page). For this particular kind of links, we added a creative idea of URL Handling: a tab that opens an additional in-app-browser over the main WebView content itself. It will look like this:

Open a link in an additional in-app-browser/tab in Android WebView apps

As you see this in-app-browser includes an address bar and navigation buttons. That’s a considerable difference to the primary, full-screen WebView content. So this kind of combination of app and browser experience is great for tutorials, knowledge databases, and all type of content that requires any type of navigation. To use this kind of in-app-browser, link to an URL in this format:

<a href='#' onClick="top.location.href='https://www.google.com';">Open Google</a>

Please insert https://www.webviewgold.com/demo/testlinks.php as WebView URL to test how your app will handle different types of links. You can open the same domain https://www.webviewgold.com/demo/testlinks.php in your desktop browser and see the source code to copy & paste the way of link.