0

I'm aware that this has been asked plenty of times. But for the life of me I can't seem to get it to work with all those solutions.

I'm using cordova 3.5 + jquery mobile(for designing) + some js plugins.

These are the things i've tried and done rnd with:

navigator.app.loadUrl("http://google.com", {openExternal : true});

<a onclick="navigator.app.loadUrl('https://google.com/', { openExternal:true });">Link</a>

Here I get the error navigator not found and the links just keep opening inside the app.

Then I follower some ideas from here:

<access origin="http://alunny.github.com" browserOnly="true" />

In this the browserOnly gets changed when I build it using cordova and then obviously the change doesn't happend.

One more way I then found using a JS function is:

<script type="text/javascript">
           $('a[target=_blank]').on('click', function(e) {
           e.preventDefault();
           window.open($(this).attr('href'), '_system');
           return false;
       }); 
    </script>

Here too nothing happens.

I should mention most of these are last year's answers and none mention Cordova 3.5.0-0.2.6.

Hence I start this thread for this specific version, I'd really appreciate some help. The phone I'm testing on is Moto G running Android 4.4.4.

allwynmasc
  • 393
  • 5
  • 18

2 Answers2

2

The answer accepted in the link provided by sagar is the solution.I tried in motog running android 4.4 and it is working fine.Added this window.open( 'http://www.google.de', '_system'); and installed the inapp browser plugin in the project directory.

My cordova version is 3.4 but i think that shouldnt make a difference

Link I followed http://community.phonegap.com/nitobi/topics/open_external_links_in_system_browser_phonegap_build_3_1_iphone_android_windows

Have posted a sample test project i created based on the example u needed https://gist.github.com/rahulinaction/f5d347ea9c74a941273e

rahulinaction
  • 344
  • 4
  • 14
  • i tried it. The browser does open but not as a separate application but within my app itself such that the user has to press back on the browser then to come back to the app which is not the usual flow. The URL must open in the browser as a separate app itself and my app should still be available. Hope i'm explaining it clearly. How did it actually work for you? I'll still try the phonegap link you shared, looks like a new approach. Thanks. – allwynmasc Sep 30 '14 at 04:41
  • i tried the answer in the link. My config.xml file automatically resets and everything i add is deleted, so no change takes effect. The config I edited is the one inside in the root not the one right in the first directory. Which one to actually edit? – allwynmasc Sep 30 '14 at 05:14
  • The config.xml is near the project you created from the commandline.Dont edit a symlinked config.xml. – rahulinaction Sep 30 '14 at 08:57
  • what's symlinked config.xml? The one inside in the root? – allwynmasc Oct 04 '14 at 07:13
  • i got this to work by writing the code: $('a').on("click",function(event){ event.preventDefault(); var anchor = $(this); var value = anchor.attr("href"); window.open( value, '_system'); }); outside of function onDeviceReady but inside doc ready! – allwynmasc Oct 05 '14 at 15:06
0

Here is a simple demo:

<h1 onclick="window.open('yourWebsiteAddress')">HELLO THERE EVERYONE</h1>

Also you need to add the cordova plugin:org.apache.cordova.inappbrowser

Use this link.

Community
  • 1
  • 1
Sagar Devanga
  • 2,815
  • 27
  • 30
  • I've tried this. Plus that link further mentions i need to install inappbrowser plugin which is missing in your answer. How did you go about it? – allwynmasc Sep 29 '14 at 09:17
  • the link is your answer I just gave you a demo – Sagar Devanga Sep 29 '14 at 09:25
  • you sure there is "core" in the plugin URL? The link doesn't have it. Is that what you tried? And it doesn't work when I tried on Moto G. – allwynmasc Sep 29 '14 at 09:49
  • @Gallwynmasc see his edit where he removed core from the plugin URL. It should work. – HischT Sep 29 '14 at 20:21
  • @HischT I've tried that method already. It did not work as needed. Like i mentioned in the comment below. The browser does open but not as a separate application but within my app itself such that the user has to press back on the browser then to come back to the app which is not the usual flow. The URL must open in the browser as a separate app itself and my app should still be available. Hope i'm explaining it clearly. How did it actually work for you? I'll still try the phonegap link you shared, looks like a new approach. – allwynmasc Oct 02 '14 at 11:32