3

I am new to PhoneGap and Android.I am unable to access Extrenal URL' like google from PhoneGap,i tried Iframe and Window.Location.Href but not sure why it's not working.

<!DOCTYPE HTML>
<html>
<head>
<title>PhoneGap</title>
<script type="text/javascript" charset="utf-8" src="phonegap-0.9.3.js"></script>


<link rel="stylesheet" href="jquery.mobile-1.0a1.min.css" /> 
<script src="jquery-1.4.3.min.js"></script> 
<script src="jquery.mobile-1.0a1.min.js"></script>

</head>
<body>
<iframe src="http://www.google.com"></iframe> 
</body>
</html>
AnoojNair
  • 491
  • 3
  • 11
  • 18

3 Answers3

11

Have you added the external URLs to the whitelist? There is a file in /res/xml in your project called PhoneGap.xml

Here is an example of one of my PhoneGap.xml files:

<?xml version="1.0" encoding="utf-8"?>
<phonegap>
    <access origin="http://127.0.0.1*"/>
    <access origin="http://devgeeks.org"/>
    <access origin="http://*.phonegap.com"/>
    <log level="DEBUG"/>
</phonegap>
Devgeeks
  • 5,659
  • 4
  • 28
  • 35
  • this is added but how to call from java script .... navigator.app.loadUrl('http://google.com'); is NOT working – Aamir Shah Nov 13 '12 at 12:16
6

Opening an external link in phonegap / android is only possible two ways: Source: https://build.phonegap.com/blog/access-tags

check blogpost of phonegap. They're explaining what the android default is, and what you can do about it.

Follow the discussing on the phonegap forum: http://community.phonegap.com/nitobi/topics/make_links_use_external_broswer_consistently

Edit:

  1. Add the following code to your config.xml.

     <access origin="http://www.domain.com" browserOnly="true" />
    
  2. Add:

     function loadURL(url){ 
        navigator.app.loadUrl(url, { openExternal:true }); 
     } 
    
  3. Add:

     <a onclick="loadURL('http://www.domain.com')" href="#">Url</a>
    
brutusmaximus86
  • 264
  • 2
  • 7
1

The access xml helped me. You can use the navigator.app.loadUrl function to get the url loaded in the current webview - look in the cordova.js file for details of the options

wattostudios
  • 8,666
  • 13
  • 43
  • 57
Gavin
  • 11
  • 1