4

All I need to do is to open a external webpage link into iPad's browser (Safari, Chrome, etc) from an App Link.

PhoneGap 3.1 says it could be done through a plugin called InAppBrowser. Fine, I installed it and added these following lines in the config.xml

  <plugin name="InAppBrowser" value="CDVInAppBrowser" />
    <feature name="InAppBrowser">
        <param name="ios-package" value="CDVInAppBrowser" />
    </feature>
    <access origin="*"/>

I then added a link in my page, which needs to open the webpage:-

<a class="linkexternal" href="#">asdf</a>

with the following JS

    <script type="text/javascript">
        $(document).on('click', ".linkexternal", function (e) {
            e.preventDefault();
            //window.open('http://apache.org', '_blank', 'location=no');
                       window.open('http://apache.org', '_system', 'location=yes');

        });
    </script>

It does open the page, but just opens spanning all over the screen with no controls. In the older version of PhoneGap, it showed me "Done" at the end, so that when I pressed the Done button, it used to bring me back to the app. But here, it shows me the whole page as the full screen and the only way to go back to the app is closing the app.

I just need it to show me the Done button either or just open the link in an external browser.

Additional Information

I tried open these three different links as a test; with '_system', '_blank' and '_self'

    <a href="#" onclick="var ref = window.open('http://google.com', '_system');">Google (System Browser)</a><br /><br />
    <a href="#" onclick="var ref = window.open('http://google.com', '_blank');">Google (InAppBrowser)</a><br /><br />
    <a href="#" onclick="var ref = window.open('http://google.com', '_self');">Google (Webview)</a>

When I test these three links with '_system', '_blank' and '_self', only '_self' one opens as a full screen for the app, the rest give me the following error:-

_system link gives this error:-

2013-11-12 11:44:58.878 XYZ[2063:60b] Failed to load webpage with error: The operation couldn’t be completed. (NSURLErrorDomain error -999.)

_blank link gives this error:-

2013-11-12 11:46:13.997 XYZ[2063:60b] CDVWebViewDelegate: Navigation started when state=1
2013-11-12 11:46:13.997 XYZ[2063:60b] Failed to load webpage with error: CDVWebViewDelegate: Navigation started when state=1
2013-11-12 11:46:13.999 XYZ[2063:60b] Resetting plugins due to page load.
2013-11-12 11:46:14.009 XYZ[2063:60b] Failed to load webpage with error: The operation couldn’t be completed. (NSURLErrorDomain error -999.)
halfer
  • 18,701
  • 13
  • 79
  • 158
Steve
  • 2,386
  • 7
  • 42
  • 87
  • Well since `_system` will open it in the system browser (Safari or whatever) and since Safari doesn't have a done button normally, you wouldn't expect to see one. You should use the `_blank` if you want that done button. I wonder why it isn't opening in `_blank` - did you add the external URL to your whitelist? Can you get to the external link from the regular browser on your phone? – MBillau Nov 12 '13 at 16:51
  • Yes, I could access the link in my browser. I added `` in my config.xml, but still this is happening. – Steve Nov 12 '13 at 16:53
  • Are you using the CLI and making these changes in the top level /www/ folder? You shouldn't need to edit the config.xml - the tools will edit that for you. This might somehow be tangentially related to your problem, for example, if you were editing the config in the ios directory and then running `cordova build`, it would wipe out your config file with the top level one (thereby wiping our your `access origin="*"`... – MBillau Nov 12 '13 at 16:55
  • I am making all my changes in the /platform/ios/www folder. For the config.xml, I am making changes in the top level config.xml. There's one in www/ folder too. I did try making changes to it too. – Steve Nov 12 '13 at 17:21
  • 1
    Are you running the command line build tools? You say you are using phonegap (cordova) 3.1 so you should have done things like `cordova(phonegap) plugin add org.apache.cordova.inappbrowser` then `cordova build` and `cordova run`? If you are, then all of your work should be done in the top level `/www/` folder, NOT in `/platforms/*`. – MBillau Nov 12 '13 at 18:23
  • 1
    Please check out the guide for using the CLI and this answer where I try to explain how the file system works: http://stackoverflow.com/questions/19112436/should-a-phonegap-plugin-be-declared-in-the-config-xml-file/1912586 cli guide: http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface – MBillau Nov 12 '13 at 18:23
  • Can you share what is in your shouldStartLoadWithRequest: UIWebViewDelegate method? – gro Jun 19 '14 at 13:03

2 Answers2

-1

Please try;

var urlToOpen = 'http://www.google.com';
navigator.app.loadUrl(urlToOpen, { openExternal: true });
Teoman shipahi
  • 43,086
  • 13
  • 113
  • 137
-1

I think the problem is href="#". With this in the tag the onClick doesn't fire and I think NSURLErrorDomain error -999 means the browser couldn't resolve "#"

TimL
  • 193
  • 10