How to open new tab in JavaScript without switching to the new tab?

前端 未结 8 1039
时光取名叫无心
时光取名叫无心 2020-11-29 04:11

How can I open a new tab using javascript without switching to the new tab?
For example, when a user clicks on a link a new tab is to be opened, but the user should stay

8条回答
  •  时光取名叫无心
    2020-11-29 04:30

    Unfortunately, you can't do this in ALL browsers, but you can do this in Chrome if you implement browser's extension. How to manipulate with tabs in Chrome by javascript:

    http://code.google.com/chrome/extensions/tabs.html

    chrome.tabs.create(object createProperties, function callback)
        Creates a new tab. Note: This function can be used without requesting the 'tabs' permission in the manifest.
    Parameters
        **createProperties** ( object )
        **windowId** ( optional integer )
           The window to create the new tab in. Defaults to the current window.
        **index** ( optional integer )
           The position the tab should take in the window. The provided value will be clamped to between zero and the number of tabs in the window.
        **url** ( optional string )
           The URL to navigate the tab to initially. Fully-qualified URLs must include a scheme (i.e.    'http://www.google.com', not 'www.google.com'). Relative URLs will be relative to the current page within the extension. Defaults to the New Tab Page.
        **selected** ( optional boolean )
           Whether the tab should become the selected tab in the window. Defaults to true
        pinned ( optional boolean )
           Whether the tab should be pinned. Defaults to false
        **callback** ( optional function )
    

提交回复
热议问题