Javascript - Open a given URL in a new tab by clicking a button

前端 未结 13 466
一生所求
一生所求 2020-12-04 13:35

I would like to have a button that redirects to a given URL and opens in a new tab. How can this be done?

13条回答
  •  一生所求
    2020-12-04 14:41

    You can forget about using JavaScript because the browser controls whether or not it opens in a new tab. Your best option is to do something like the following instead:

    This will always open in a new tab regardless of which browser a client uses due to the target="_blank" attribute.

    If all you need is to redirect with no dynamic parameters you can use a link with the target="_blank" attribute as Tim Büthe suggests.

提交回复
热议问题