How to open a link in new tab using javascript

前端 未结 5 1345
醉话见心
醉话见心 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:48

    You can use:

    window.open(url,'_target')
    

    _target opens the page in next tab.

    0 讨论(0)
  • 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.

    <div onclick="OpenInNewTab('www.test.com');">Something To Click On</div>
    

    Please also try this:

    Add your form name attribute like:

    <form name="form">
    

    and then try it like that:

    <a href="" onclick="window.open( form.url.value, 'windowName' ); return false" target="_blank">Submit</a>
    

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

    0 讨论(0)
  • 2021-01-02 04:54
    <a href="javascript:" onclick="window.open('https://www.google.co.in');" target="_blank">Sample Code</a>
    
    0 讨论(0)
  • 2021-01-02 04:55

    Html Code :

    <button onclick="OpenInNewTab();" type="submit">
    

    Javascript Code :

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

    Change Your Browser Setting.

    In FireFox ,

    Go To Options -> Tab setting and Check "Open New Windows in a New Tab instead" setting.

    This Solution Worked For me .

    0 讨论(0)
  • 2021-01-02 04:58

    I think answer to this question will help , Open a URL in a new tab using JavaScript https://stackoverflow.com/a/30512485/2293686

    try like this,

    $('#myButton').click(function () {
        var redirectWindow = window.open('url', '_blank');
        redirectWindow.location;
    });
    
    0 讨论(0)
提交回复
热议问题