I am trying to open a new tab using js.
$("#hello").attr("href", "https://www.youtube.com/");
setTimeout(function() {
$("#hello")[0].click()
}, 1000);
<a id="hello" target="_blank">Hello</a>
The problem with this approach is that a browser is asking user permission to open new tab. But when I click on that <a>
tag, a browser is opening new tab without asking permission from user.
Why does this type of behavior happen?
Fiddle link:- https://jsfiddle.net/90chntz4/5/
I try this one also:- Allow window.open to open new window and not popup
but It is not working.
How can I open new tab without asking permission from user?