How to open a link in new tab using javascript

前端 未结 5 1367
醉话见心
醉话见心 2021-01-02 04:31

I am working on a website, in which I have to open a url from backend. I am using c# now. My problem is that I want to open link in new tab instead of new window.

M

5条回答
  •  情话喂你
    2021-01-02 04:53

    Have you try this code: Originally shared here

    function OpenInNewTab(url )
    {
      var win=window.open(url, '_blank');
      win.focus();
    }
    

    In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers and the default "new window" behavior. You could do it this way or by adding an event listener to your DOM object.

    Something To Click On

    Please also try this:

    Add your form name attribute like:

    and then try it like that:

    Submit
    

    and check this link http://jsfiddle.net/ef69K/

提交回复
热议问题