Is there a way to make a click event have the same behavior as after clicking a link?
تبليغيرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.
When we click a link like <a href=”https://stackoverflow.com/”>A link</a>, the current page will be redirected to the given URL. But we’ll be led to a new tab if we cmd/ctrl+click it. I wonder that is there a browser interface(something like window.open()) in JS that can give the click event of a non-a tag the same behavior above? The solution I got from the Internet is all about detecting e.metaKey/ctrlKey to decide whether to add _blank to the window.open() or not. The solution is tricky and still has some differences from the expected behavior. Maybe we can just simply use the <a> tag directly to avoid this. But can this be the solution for all situations? And could you guys please give me the reason if there’s indeed not a pure JS way to simulate the event? Cuz it’s weird to me.
أضف إجابة