problems with InAppBrowser on dynamic links

user1009453

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.

Adnan Topal

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

External links / InAppBrowser in Cordova / Phonegap 3.3 always behave like "_self"

From Dev

Angular Marked and Inappbrowser opening all links in the system browser

From Dev

External links don't open in the inAppBrowser on iOS on phonegap 2.9.0

From Dev

Cordova, why would InAppBrowser plugin be required to open links in system browser

From Dev

Angular Marked and Inappbrowser opening all links in the system browser

From Dev

Dynamic links with PHP

From Dev

Dynamic Links in php and mysql

From Dev

Dynamic links with JavaScript

From Dev

Angularjs & php dynamic links

From Dev

Problems with scrolling inside a div by links

From Dev

Problems with database links on phpmyadmin interface

From Dev

Problems with shuffling array of HTML links

From Dev

Having problems following links with webcrawler

From Dev

Problems with database links on phpmyadmin interface

From Dev

Problems with scrolling inside a div by links

From Dev

Problems creating symbolic links on Mac

From Dev

Problems with shuffling array of HTML links

From Dev

Problems with dynamic parameter

From Dev

Problems in Binding To Dynamic Table

From Dev

problems on dynamic dropdown lists

From Dev

Javascript make dynamic links but ignore existing links

From Dev

Javascript make dynamic links but ignore existing links

From Dev

Nesting dynamic links into a dynamic list with Javascript

From Dev

fpdf: multiple dynamic links with dynamic varnames

From Dev

Dynamic creation of SVG links in JavaScript

From Dev

rewrite url for videos with dynamic links

From Dev

Firebase dynamic links handled twice

From Dev

PHP/MySQL Table dynamic links

From Dev

Using dynamic links to trigger ajax

Related Related

HotTag

Archive