Veet Vivarto
Veet Vivarto

Reputation: 361

How to open a new default browser window in Python when the default is Chrome

I have been looking for a way to open a new default browser window from inside Python code.

According to the documentation webbrowser.open_new(url) Should do that. Unfortunately in case Chrome is the default browser it only opens a new tab. Is there any way to open the default browser (without knowing what that browser is)?

Upvotes: 10

Views: 7682

Answers (4)

infrared
infrared

Reputation: 3626

webbrowser.open('http://www.google.com', new=1)

or

webbrowser.open_new('http://www.google.com')

Upvotes: -1

Ryan Cocuzzo
Ryan Cocuzzo

Reputation: 3219

import subprocess

def open(url):
    cmd = "open " + url
    print(cmd)
    subprocess.Popen(cmd, shell=True)

Upvotes: 1

Phaxmohdem
Phaxmohdem

Reputation: 531

Give this a whirl:

import subprocess
command = "cmd /c start chrome http://www.ebay.com --new-window"
subprocess.Popen(command, shell=True)

Upvotes: 6

TorelTwiddler
TorelTwiddler

Reputation: 6156

I have a feeling it's not Python's fault. Firefox and Chrome (and probably IE) all intercept calls to open new windows and changes them to new tabs. Check the settings in your browser for interpreting those calls.

Upvotes: 2

Related Questions