Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load and navigate a website within a Cordova webview

Hello I have built my website, was looking forward to have an app for my responsive website... I went with android webviews but it posed problems with opening filechooser... So I went with Cordova after doing a lot of research. I succeeded in creating a Cordova application an imported it to Android studio. My problem is, when my landing page opens clicking any other link opens the default browser... I don't want this behavior I want all links to open within the app(Using Cordova's webviews)...thanks in advance.

NOTE:Am using Cardova to open a completely remote website no local stuff.

My MainActivity.java look like this

package com.noel.myapp;

import android.os.Bundle;
import org.apache.cordova.*;

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // Set by <content src="index.html" /> in config.xml
        loadUrl("http://www.mywebsite.com");
    }
}
like image 972
Fenn-CS Avatar asked Oct 26 '25 10:10

Fenn-CS


1 Answers

The inAppBrowser adds an additional address bar at the top. Instead if you just want in app navigation you can use this solution (borrowed from comment section of this answer)

Add this line in your config.xml file

<allow-navigation href="*://*.example.com/*" /> 

and inside your index.js add something like this

receivedEvent: function(id) {
    // other code
    window.location = "https://www.example.com
}

(Although this being an old thread sharing anyways if someone else comes across this)

like image 101
akashperfect Avatar answered Oct 29 '25 01:10

akashperfect