cordova - PhoneGap InAppBrowser: open iOS Safari Browser -
in our phonegap ios application, using inappbrowser plugin display content, , need open page in safari within inappbrowser.
how can have links within inappbrowser open in safari?
from phonegap documentation:
opens url in new inappbrowser instance, current browser instance, or system browser.
var ref = window.open(url, target, options);
- ref: reference inappbrowser window. (inappbrowser)
- url: url load (string). call encodeuri() on if url contains unicode characters.
target: target in load url, optional parameter defaults _self. (string)
- _self: opens in cordova webview if url in white list, otherwise opens in inappbrowser.
- _blank: opens in inappbrowser.
- _system: opens in system's web browser.
so answer question, use:
window.open(your_url, '_system', opts);
note domain need white-listed.
update 4/25/2014:
i think kind of misunderstood question (thanks commenter @peteorpeter) -- want have way click link in inappbrowser , have open in system browser (e.g. mobile safari on ios). possible, require forethought , cooperation between app developer , person responsible links on page.
when create iab instance, reference back:
var ref = window.open('http://foo.com', '_blank', {...});
you can register few event listeners on reference:
ref.addeventlistener('loadstart', function(event){ ... });
this particular event fired every time url of iab changes (e.g. link clicked, server returns 302, etc...), , can inspect new url.
to break out system browser, need sort of flag defined in url. number of things, example let's assume there's systembrowser
flag in url:
.....html?foo=1&systembrowser=true
you'll flag in event handler, , when found, kick out system browser:
ref.addeventlistener('loadstart', function(event){ if (event.url.indexof('systembrowser') > 0){ window.open(event.url, '_system', null); } });
note not best method detecting flag in url (could lead false positives, possibly) , i'm pretty sure phonegap whitelist rules still apply.
Comments
Post a Comment