Open a new tab with javascript but stay on current tab

后端 未结 4 1023
感动是毒
感动是毒 2020-11-27 21:58

Is it possible to open a new tab in Firefox (in background) using window.open(\"http://www.google.com\") function, and remain the current tab?

Thanks fo

相关标签:
4条回答
  • 2020-11-27 22:16

    Here's an idea:

    <script>
    function open_in_bg(c_url, n_url)
    {
     window.open (n_url, "mywindow" );
     window.open (c_url+"#maintain_focus","_self");
    }
    </script>
    
    <input type="button" onclick="open_in_bg('current_page_url', 'url_to_be_opened')" />
    
    0 讨论(0)
  • 2020-11-27 22:17

    Whether or not to focus a new tab when it is opened is a browser setting and not something that you can control.

    Opening links in a new tab at all (rather than a separate window) is a browser setting too, so you're facing an uphill battle with this one.

    Basically, leave it up to the user to decide how they want to open links.

    0 讨论(0)
  • 2020-11-27 22:21

    You can't open tabs in the background using javascript because this is set in the user's preferences in about:config, which you have no control over. The setting is:

    browser.tabs.loadDivertedInBackground=true
    
    0 讨论(0)
  • 2020-11-27 22:23

    I know you said JavaScript, OP, but, I feel the heart of the matter for you is just opening the html links in and of themselves in a new tab.

    In which case, simple add ' target="_blank" ' inside your link tags:

    <a href="example.com" target="_blank"> random stuff</a> 
    
    0 讨论(0)
提交回复
热议问题