I am trying to create a link by means of the tag "a", click this link and open it in a new tab. My script works but does not open the link in a new tab does it on the same page.
The script is activated by clicking on the "body" element of the web page. Apparently the target = '_blank' is not working.
<script>
function openInNewTab(url) {
var a = document.createElement("a");
a.target = '_blank';
a.href = window.location.href;
a.click();
window.location.href = 'https://www.google.com.pe';
}
$("body").click(function () {
openInNewTab();
});
</script>