Phonegap does not open external site!

Asked

Viewed 1,137 times

3

I’m starting with Phonegap, and I found a problem: my app would need to open a Facebook page. But I can’t get the Phonegap App to open a simple Globo.com page (example), but through the Desktop I can normally!

index.html:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Security-Policy" content="default-src *; script-src *; object-src *; style-src *; img-src *; media-src *; frame-src *; font-src *; connect-src *">    
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>Hello World</title>
    </head>
    <body>
    <br><br>
        <a href="www.globo.com">GLOBO</a>

        <iframe src="www.google.com/"></iframe>

        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script>

        </script>
    </body>
</html>

My config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.hello" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>HelloWorld</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="[email protected]" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-navigation href="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

Can someone help me solve this situation?


Solved! The problem I believe is in the Phonegap App, because the Android apk worked normally!

  • It wouldn’t be because the http:// at the beginning of the URL? When you use href="www.coisa.com" he will go to phonegap/www.coisa.com, EXAMPLE, instead of going to http://www.coisa.com, which is the website.

  • Yes, I’ve tried it too and it doesn’t work. The <a> I was able to change and make it work with Jquery. $("#face"). click(Function() { window.open("https://www.facebook.com/xxxx/", "_system"); });

2 answers

5


Guilherme, Phonegap in its own documentation has a detailed explanation regarding internet access through the App. Follow the link:

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/#supported-Cordova-Platforms

I recommend that you read, because it is of great help.

Run the following commands in your terminal, in your application directory:

$ cordova plugin add cordova-plugin-whitelist
$ cordova prepare

(If it’s windows, you don’t need $)

And add the following line to your config.xml:

<allow-navigation href="*" />

This line basically gives you the authorization to access all web pages through your application.

NOTE: In your config.xml, check if it has any other tag <allow-navigation>, if you have, you can delete it and copy the one I passed on.

2

In my case to work I inserted in xml that line

<plugin name="cordova-plugin-whitelist" source="npm" spec="~1.3.3"/>

And that line

<allow-navigation href="*" />

I converted into phonegap build, maybe it’ll help ^^

Browser other questions tagged

You are not signed in. Login or sign up in order to post.