I have this code in start.html of my phonegap build app.
document.addEventListener('deviceready', function() {
try {
function appBrowser(url) {
var ref = window.open(url, '_blank', 'location=yes');
ref.addEventListener('loadstart', function() { alert('start: ' + event.url); });
ref.addEventListener('loadstop', function() { alert('stop: ' + event.url); });
ref.addEventListener('exit', function() { alert(event.type); });
}
} catch (e) {
alert(e);
}
}, false);
If I just statically put this html below, everything works fine.
<a href="" onClick="javascript:appBrowse('http://www.link.se')">Link</a>
I then try to add the link dynamically to a div on the sama page (with class link), with this, called from js/index.js.
$('.link').append("<a href='' onClick='appBrowser("+ encodeURI(link) + ")'>Test</a>");
The link gets added, but when I click the link I get following error: Uncaught SyntaxError: Unexpected token : start.html:1
Any ideas? I'm using jquery mobile as my front end.
Why don't you bind a click event on those specific links by their class instead of using onclick?
$('body').on('click', '.appBrowser', function(e) {
e.preventDefault();
var url = $(this).attr('href');
window.open(url, '_blank', 'location=yes');
});
Give the links which will be opened with inAppBrowser the class appBrowser
, and they'll be opened using inAppBrowser.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments