简体   繁体   中英

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)?

Give this a whirl:

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

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.

import subprocess

def open(url):
    cmd = "open " + url
    print(cmd)
    subprocess.Popen(cmd, shell=True)
webbrowser.open('http://www.google.com', new=1)

或者

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM