Opening a URL with Default Browser
suggest changeTo simply open a URL, use the webbrowser.open() method:
import webbrowser
webbrowser.open("http://stackoverflow.com")
With the default new=0, the method tries to open the URL in the same browser window. If no window is open, it opens the operating system's default browser. The open method supports the following parameters:
url- the URL to open in the web browser (string) [required]new- 0 opens in the same browser window, 1 opens a new window, 2 opens a new tab (integer) [default 0]autoraise- if set to True, the window is raised if possible (Boolean) [default True]
Note, the new and autoraise arguments rarely work as the majority of modern browsers refuse these commands.
Webbrowser can also try to open URLs in new windows with the open_new method:
import webbrowser
webbrowser.open_new("http://stackoverflow.com")
This method is commonly ignored by modern browsers and the URL is usually opened in a new tab. Opening a new tab can be tried by the module using the open_new_tab method:
import webbrowser
webbrowser.open_new_tab("http://stackoverflow.com")
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents