Opening link inside inner html content in external browser of mobile app
Application Type


We are using a Javscript to load inner html content inside a container of mobile app. The HTML content is coming from RestAPI. Now if the user clicks on link ('a') it is opening inside the app and not opening in external browser. I tried many Javascript codes below and nothing worked out.

Code 1:

links = document.getElementsByClassName("video-content")[0].getElementsByTagName("A");var i;for (i = 0; i < links.length; i++) {links[i].onclick=function(){window.open( this.href, '_system' ); this.href = "javascript:void(0)"; this.preventDefault();};}

Code 2:

var el = document.getElementById($parameters.Container);
el.innerHTML = $parameters.HtmlContent;
var tempDiv = document.createElement('div');
tempDiv.innerHTML = $parameters.HtmlContent;
var anchors=tempDiv.getElementsByTagName('a');
var i, len = anchors.length;
var linkArray=[];
for( i = 0; i < len; i++ ) {
   if (i === 0)
   window.open(anchors[i].getAttribute('href'), '_system');

Code 3:

var tempDiv = document.createElement('div');tempDiv.innerHTML = $parameters.HtmlCont;var anchors=tempDiv.getElementsByTagName('a');var i, len = anchors.length;for( i = 0; i < len; i++ ) {   anchors[i].setAttribute('href', "javascript:window.open('"+anchors[i].getAttribute('href')+"','_system')");}document.getElementById('HtmlCont').innerHTML = tempDiv.innerHTML;

Any idea on how to achieve this or anything blocked by mobile app JS code to open the link in external browser? Thanks

Balaji Chandran

I'm not sure if it is best practice to open an external browser directly from you app. I have no personal experience creating this but apps that I use all make use of an InAppBrowser instead.

You can also do this yourself. There is an InAppBrowser component that opens a browser view inside your own app. 

Hope this helps,


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.