On android target='_blank' is not working, Links open in webview

edited November 2012 in Newbie Questions
I am trying to parse tweets for "#" and "@",
 parseTweet: function(text) {
              var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;
              text = text.replace(exp, "<a href='$1' target='_blank'>$1</a>");
              exp = /(^|\s)#(\w+)/g;
              text = text.replace(exp, "$1<a href='https://search.twitter.com/search?q=%23$2' target='_blank'>#$2</a>");
              exp = /(^|\s)@(\w+)/g;
              text = text.replace(exp, "$2<a href='https://twitter.com/$2' target='_blank'>@$2</a>");
              return text;
but clicking on links, open with in the webview of android, and there is no way to go back to app,

It is working fine with iOS.

Can anybody suggest on this?


  • I assume you are using Cordova/PhoneGap?! I was not able to figure out how to force opening links in the external browser. One workaround is to limit the white list only to those URLs where you need to fetch data from (you should do that anyway). All URLs not on the white list will be opened in the external browser. If more than one is installed, the user has to choose the preferred browser.
  • Yes I am using Cordova 2.1.0, Data is coming from n number of URLs, Some are dynamic. I cannot list all to the whitelist, I gave "*" in the config.xml.

    Is there any way we can do this?
  • You should not list them on your white list, but you currently do as * will match every URL. Remove the * and only add URLs in your config.xml where you need to fetch data from (via Ajax or Cordova file API).
  • edited November 2012
    You can do this programmatically from javascript via navigator.app.loadUrl("http://www.example.com/", { openExternal: true });

    Its not in the API docs, but is documented in the js file:
  • Thank you, that is really helpful. It is a pity, that it is not in the docs. I used the white list workaround so far, but to open the URLs explicitly external is far better.
  • Sad but true, this does not work on iOS. :(
    (At least with Cordova 2.2)
  • What I found after doing so much R & D on google is Whitelisting in android and iOS is different, I put '*" for iOS and give domain name from where my data is coming in Android for example "*.example.com" .

    This is working for me.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!