I want to configure Capacitor to open all links like:
<a href="https://www.google.com" target="_blank">Google Link</a>
within Capacitor's In-App Browser feature. I know I can open it by using the open()
Method of the Browser API
, but some of my HTML content (and so it's links) are coming from the database. Currently on iOS and Android, my apps open the link above with an external Browser such as Safari.
Sources:
https://capacitor.ionicframework.com/docs/apis/browser
Edit - My current solution which I do not really like:
if (this.$q.platform.is.capacitor) {
document.onclick = function(event: any): boolean | void {
const element: any = event.target || event.srcElement;
if (element.tagName === 'A' && element.target === '_blank' && element.href) {
event.preventDefault();
Browser.open({ url: element.href });
return true;
}
};
}