I am trying to open external links in the inAppBrowser in Cordova using Phonegap Build. My links are dynamically added based on results pulled from the database, and I am using this code in my initializer:
document.onclick = (e) ->
e = e or window.event
element = e.target or e.srcElement
if element.tagName == 'A'
cordova.inAppBrowser.open element.href, '_blank', 'location=yes'
return false
# prevent default action and stop event propagation
return
This doesn't seem to do anything in my compiled app though, it just opens the link in the viewport of the app and then I have to exit the app to get back to my application.
This is the entry in my config.xml
file
<gap:plugin name="org.apache.cordova.inappbrowser"/>
Also, in my Javascript console on development, cordova.inAppBrowser
is undefined. I am fairly new to Cordova/Phonegap development, what am I doing wrong to use plugins/the inAppBrowser?
change your
<gap:plugin name="org.apache.cordova.inappbrowser"/>
to
<gap:plugin name="cordova-plugin-inappbrowser" source="npm"/>
You are using an old version of the plugin and cordova.InAppBrowser.open
function was added recently, in previous version you have to open the inAppBrowser with window.open
instead