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

前端 未结 13 490
一生所求
一生所求 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:21

    Use window.open instead of window.location to open a new window or tab (depending on browser settings).

    Your fiddle does not work because there is no button element to select. Try input[type=button] or give the button an id and use #buttonId.

提交回复
热议问题