This is a migrated thread and some comments may be shown as answers.

Open ad links in an external browser

1 Answer 155 Views
HTML5, CSS, JavaScript
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nathaniel
Top achievements
Rank 1
Nathaniel asked on 25 Sep 2015, 06:56 PM

In my app I use JWPlayer to show videos and ads. If a user clicks on an ad in a video, my entire webview (and app) redirects to the ad URL which makes my app useless until it's restarted.

When I want to manually direct a user to a webpage, I currently use:

function nav() {
    if (kendo.support.mobileOS.android) {
        navigator.app.loadUrl("http://www.google.com/", { openExternal:true } );
    } else if (kendo.support.mobileOS.ios) {
        window.open("http://www.google.com/", '_system');
    } else {
        alert("something went wrong");
    }
}

But I have no control  over the links in the player.

Is there a way to adapt the code above or is there different method that would allow me to open all ad links in an external browser?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Martin Yankov
Telerik team
answered on 30 Sep 2015, 10:38 AM
Hello Nathaniel,

Thank you for contacting us.

Currently, Cordova doesn't provide a mechanism to intercept all outgoing links and modify them. You will have to come with a custom solution to fix this problem. I took a look at this player and it seems it's a HTML5 player, which is good. Furthermore, it's loaded in an iframe. So my first idea would be to try to find the links in the player and their classes. You can also try to check all clicked/tapped links like this:
$('iframe').on('click', 'a', function(e) {
    // get the href attribute value and use window.open().
    // prevent the default behavior.
});

This is only an idea. If you open a support ticket and send us a sample project I could try this out and investigate it further.

I hope this helps.

Regards,
Martin Yankov
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
Tags
HTML5, CSS, JavaScript
Asked by
Nathaniel
Top achievements
Rank 1
Answers by
Martin Yankov
Telerik team
Share this question
or