Python Glossary Русский

all Python 3webbrowserfunction

webbrowser.open_new()

opening pages

Opens a URL in a new window of the default browser when possible; the same as open(url, new=1).

Syntax

webbrowser.open_new(url)

"When possible" is literal: many browsers open a tab anyway because of their own settings, and Python cannot tell. A True result only means a browser was launched, not that the page loaded. Like open, the function does not raise when no browser is available; it returns False.

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('https://python.org'))  # → open https://python.org new = 1 / True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy