10

I'm opening a webpage in the default webbrowser on the system using python's webbrowser module.

I want to check if the site is already open in the browser and only open a new tab/window if it is not. Otherwise reload the already opened page.

Is there a way to do this with webbrowser module? If not, is there any other module i can use to do this.

2
  • 3
    that's not possible with the webbrowswer module. I'd doubt that it is possible at all. Commented Jul 5, 2010 at 13:29
  • I agree with @SilentGhost. You would need a library which is able to interface with any possible browser the user has installed. Perhaps if you gave an idea of the higher-level problem you're trying to solve, we could offer some alternative solutions. Commented Jul 28, 2010 at 5:19

3 Answers 3

3

I don't think this is currently possible with the webbrowser module. There was a bug filed for this, but it was closed with status "Won't fix":

http://bugs.python.org/issue1753371

Sign up to request clarification or add additional context in comments.

Comments

2

use

webbrowser.open( url, new=0 ) 

this tries to open the website in the same windows if possible, if you set the new parameter to 1 a new window/tab will be generated

but i'm not sure if this works reliable on all plattforms

5 Comments

well, this is not what OP asks, is it?
why not? he wants to reload the page if it already is open, otherwise open a new tab or window - this is exactly what the webbrowser.open method does according to the reference documentation
This is exactly what I'm looking for, but it doesn't work. I'm on Ubuntu Linux.
as i said - i'm not sure if this works reliable on all plattforms. It works on my mac using safari. But i didn't get firefox to reload the current tab on ubuntu - even without python.
If you look at the code, Darwin/MacOS has more support for this using AppleScript to pass a toWindow argument, while the UnixBrowser, which is used on Ubuntu, does not have such a capability. So this is in fact the right answer, but here is just no way to do it effectively on Ubuntu. +1'd
-3

From http://docs.python.org/library/webbrowser.html#webbrowser.open_new_tab:

webbrowser.open_new_tab(url)

Open url in a new page (“tab”) of the default browser, if possible; otherwise equivalent to open_new().

2 Comments

upss... I think I misunderstood the question
Might want to delete this.