This is a migrated thread and some comments may be shown as answers.
External links using Telerik Platform/Cordova without OnClick on link
1 Answer 42 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Top achievements
Rank 1
Carlos asked on 01 Feb 2016, 10:18 PM

We are using Telerik Platform, which runs on Cordova. We have dynamically pulled content from a CMS that shows some of our content in our app. Our authors want to put links in the content, but of course, I don't want them having to put an 'onclick' on the links in the Rich Text Editor in the CMS.
Is there a way to allow our authors to just enter links with a CSS class added to them or something like that, that I can capture the click, using jQuery or something, and have the link get translated in the Cordova app to open the "_system" browser.

I ultimately want my links to look like this for my authors to use when they enter them into the CMS:

<a href="" target="_blank" class="externalLink">My external link</a>

But in the PhoneGap/Telerik Platform app, I want the link to open in the system browsers. Which currently it is not, it is opening in the current webview and locks the app into the webpage without any way of getting back.
I tried this so far but to no avail. It seems like the 'href' just triggers the browser to go and then the app gets caught in the webview browser and won't go back without force quitting the app.


   //Don't even think this works
 $('a.externalLink, a[target="_blank"]').on('click', function(e){
   e.preventDefault();// Does not prevent default
   console.log("trying to get system");//Does not console
   alert("prevent default"); // Does not alert$(this).attr('href'), '_system');
    return false;


It seems that the link that gets entered into the CMS just directs to the 'href' link and ignores the above jQuery. Any way to catch it before the webview catches it?

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 04 Feb 2016, 11:51 AM
Hi Carlos,

What I tried in my test app and it worked is:
$(".externalLink").click(function (e) {
    e.stopPropagation();, "_blank");

However, the most important thing is that this code runs after the external content has loaded. Have you debugged your app to confirm that the jQuery selector returns any result before you attach the click event?

In my app, where I render my external content inside a Kendo UI Mobile ListView, I wait for the ListView to bind and then add a small timeout to ensure content is rendered.

You can find a sample project attached where I open your exact same link in the InAppBrowser. I hope this solution works for you, too.


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

AppBuilder Windows client
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question