Links won't open in webview using CLI-5.2.0

  • 1
  • Problem
  • Updated 4 years ago
  • Solved
Hi,

Since the release of 5.2.0, links won't open inside the app's webview any longer. Instead, the apps open in the device's browser. This is the opposite of how links used to work. Before 5.2.0, all links opened in webview by default. Does anyone have a solution? I don't want to use the inappbrowser. I'm just trying get a website to load directly in the app's webview.

Here's my preferences from my config.xml

preference name="phonegap-version" value="cli-5.2.0" /

preference name="webviewbounce" value="false" /

preference name="load-url-timeout" value="150000" /

preference name="stay-in-webview" value="true" /

access origin="*" browserOnly="true" /

gap:plugin name="cordova-plugin-whitelist" source="npm" /

In my index.html

a href="http://www.google.com" (just a regular link)
Photo of John W.

John W.

  • 3 Posts
  • 0 Reply Likes

Posted 5 years ago

  • 1
Photo of Amir

Amir

  • 8261 Posts
  • 263 Reply Likes
Your code is not showing. Please repost within <code></code> tag.
Photo of John W.

John W.

  • 3 Posts
  • 0 Reply Likes
Thanks for getting back to me. Here in my relevant code in the config.xml:



<preference name="phonegap-version" value="cli-5.2.0" />

<preference name="webviewbounce" value="false" />

<preference name="load-url-timeout" value="150000" />

<preference name="stay-in-webview" value="true" />

<access origin="*" browserOnly="true" />

<gap:plugin name="cordova-plugin-whitelist" source="npm" />


And here is my relevant code in the index.html:

<a href="http://www.google.com">Google</a>

Thanks!
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Well, you refrain from using the inAppBrowser plugin at your own risk....and this is what happens.
If you had taken over control by using the plugin, you wouldn't have had to deal with this mess.

You can still do so. The inAppBrowser plugin allows you to opens external sites in the webview, as well as in the system browser or a separate inApprowser window.
See the documentation at https://github.com/apache/cordova-plu... and especially:

target [parameter]: The target in which to load the URL, an optional parameter that defaults to _self. (String)
_self: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the InAppBrowser.
_blank: Opens in the InAppBrowser.
_system: Opens in the system's web browser.
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Petra,
the OP is missing to important components in the config.xml. However, i tend to agree with your comments and reasoning. The following is for the Original Poster to make an objective decision:

Add the following to your config.xml, they are DANGEROUS, BUT WORKING

- Whitelist Plugin Documentation


<allow-navigation href="*" />
<allow-intent href="*" />


allow-navigate - Controls which URLs the WebView itself can be navigated to. Applies to top-level navigations only.
allow-intent - Controls which URLs the app is allowed to ask the system to open. By default, no external URLs are allowed.


<access origin="*" />


access - Controls which network requests (images, XHRs, etc) are allowed to be made (via cordova native hooks).

Those comments straight from the docs. They will also go in an upcoming blog under the heading DANGEROUS, BUT WORKING

- Whitelist Plugin Documentation

Best of Luck
Jesse
Photo of Amir

Amir

  • 8261 Posts
  • 263 Reply Likes
Marked as resolved for now.
Photo of John W.

John W.

  • 3 Posts
  • 0 Reply Likes
Thank you all for your help! This resolved the issue. I appreciate it very much.
Photo of Taewook  Kim

Taewook Kim

  • 1 Post
  • 0 Reply Likes
How do I fix ?
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
You read the instructions.

This FAQ should also help. Read the bold sentences first.
Top Mistakes by Developers new to Cordova/Phonegap