Monday, May 20, 2024
58
rated 0 times [  65] [ 7]  / answers: 1 / hits: 16547  / 11 Years ago, sun, june 30, 2013, 12:00:00

I have a bunch of links in my app. I added rel='external' target='_blank' to all of them.



In the Ripple emulator, or in a regular desktop browser, this works great. But on my Android (JB 4.2.2) it opens the link in the same window. Hitting back takes me back to the app, but everything is screwed and the app does not work as planned (script events do not react), until physically reloaded.



How do I ensure that a link opens in the device's browser? Do I need to use a Cordova plugin?



(I'm using Cordova 2.9.0, jQuery 1.10.1, jQuery Mobile 1.3.1)


More From » jquery-mobile

 Answers
17

This has been really fickle with Cordova/PhoneGap in the last few releases, I believe because of the InAppBrowser work which might be a solution for you.



What is working for us to launch in the external browser is:



window.open(http://myurl.com, '_system');


In our case, we want to find all external links and launch them in Safari/Chrome (and keep internal links in our Angular router). This probably isn't the most elegant solution, but we are doing this right now by capturing input events on the links and taking over the behavior like so:



        $(document).on('mousedown','a', function(e) {
e.preventDefault();
var elem = $(this);
var url = elem.attr('href');
if (url.indexOf('http://') !== -1) {
window.open(url, '_system');
}
});


I hope that helps you a bit.


[#77292] Saturday, June 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hallie

Total Points: 503
Total Questions: 114
Total Answers: 103

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;