Open the link on your own phone.

I created a PhoneGap app with a pedestrian crossing and when I try to open a link in it,

  • it doesn't open in the same webview , furthermore it launches a browser select window.

what i want is if i am on href it should load webapp inside webview by loading default.html default.html i tried to redirect page with js too.

I'm not sure if I did the integration correctly, I just followed this link Codova Plugin

+3


source to share


3 answers


To achieve this, you need to use the inappbrowser plugin : https://github.com/apache/cordova-plugin-inappbrowser

After installing the plugin via, cordova plugin add cordova-plugin-inappbrowser

you can write something like:



<span id="myLink">Load Pap</span>

<script>
    document.addEventListener("deviceready", onDeviceReady, false);

    function onDeviceReady()
    {
        var myLink = document.getElementById('myLink');

        myLink.addEventListener("click", function()
        {
            cordova.InAppBrowser.open('http://192.168.1.11/papa', '_self', 'location=no');
        })
    }
</script>

      

+3


source


Ivan's answer is a good solution, but keep in mind that InAppBrowser opens a browser through your app, for example if you need to open an external site as well, authenticate and then return to your app in the state you left.

Have you seen this answer? Uploading remote html to PhoneGap or Cleaver (Cordova) on iOS

You can also use JS:



window.location.href = <your_remote_url>

      

Which JS have you tried?

+2


source


For those who have this problem while using Phonegap 6.3.1.

Make sure you include the url you want to open in tag <access>

, tag <allow-intent>

and tag allow-navigation

in your config.xml file (at the root of the project):

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.helloworld" version="1.0.0"
        xmlns="http://www.w3.org/ns/widgets"
        xmlns:gap="http://phonegap.com/ns/1.0">

    ...

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

    ...

</widget>

      

(Note: the "*" in the above hrefs allows any url to be visited. During production, you probably want to restrict certain urls / paths)

Then in your index.html file add the following javascript:

<script type="text/javascript">
    document.addEventListener('deviceready', function() {
        var url = 'https://www.google.com' // change to whatever you want
        cordova.InAppBrowser.open(url, '_self', 'location=no');
    }, false)
</script>

      

This script uses the cordova-plug-inappbrowser plugin, which, if you built your app using the default Phonegap template, should already be included in your config.xml file.

The script waits for the device to be ready, then uses the cordova-plug-inappbrowser plugin to open the given url. The parameter '_self'

means it opens the page in the Phonegap webview, which 'location=no'

means there will be no address bar. For other options, see the documentation for the cordova-plug-inappbrowser plugin (link above).

To test your application in the appropriate emulators (assuming you have CLG Phonegap installed ), run the following commands:

phonegap run ios --verbose --stack-trace
phonegap run android --verbose --stack-trace

      

+1


source







All Articles