Below code works well on devices where web share API is supported and shows the native share dialog but throughs "Uncaught (in promise) DOMException: Share canceled" error where web share API is not supported and do not goes to the URL defined in href of the anchor tag.
<a href="https://example.com?utm_source=btn_share" class="btn-share" target="_blank">
Share on Facebook
</a>
<script type="text/javascript">
$(".btn-share").click(function(e){
// Web Share API
if (navigator.share){
e.preventDefault();
navigator.share({
title: 'This is example website',
url: 'https://example.com'
});
}
});
</script>
Remove the error so that it should go to the URL defined in href of the anchor tag if web share API is not supported on the device.