Python Glossary Русский

all Python 3webbrowserfunction

webbrowser.open_new_tab()

opening pages

Opens a URL in a new tab of the default browser; the same as open(url, new=2). Returns True if a browser was launched.

Syntax

webbrowser.open_new_tab(url)

This is usually the most expected choice: open() with new=0 may replace the page in an already open tab. If the browser has no tabs, the call behaves like open_new. Calling it in a loop over a hundred links opens a hundred tabs without asking — limit the count.

Examples

import webbrowser
class Recorder(webbrowser.BaseBrowser):  # поддельный браузер: ничего не открывает
    def open(self, url, new=0, autoraise=True):
        print('open', url, 'new =', new)
        return True
webbrowser.register('recorder', Recorder, preferred=True)
print(webbrowser.open_new_tab('https://python.org'))  # → open https://python.org new = 2 / True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy