This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [help][webbrowser always opens new tab. I want to open in the same tab]
Type: Stage: resolved
Components: Library (Lib), macOS, Windows Versions: Python 3.6
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: cheryl.sabella, ned.deily, paul.moore, ronaldoussoren, steve.dower, tim.golden, tommylim1018@naver.com, tttnns, zach.ware
Priority: normal Keywords:

Created on 2018-02-24 02:17 by tommylim1018@naver.com, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (6)
msg312689 - (view) Author: Tommy (tommylim1018@naver.com) Date: 2018-02-24 02:17
Dear manager,

I'm just starting python and trying to make simple web application.
As above title, I just want to open webbrowser at first and then just change web-address in the same tab, but whenever I try webbrowser.open, it always open new tab or new window.
When I checked webbrowser-control options on python help page, it says webbrowser.open's 2nd argument can control window opening. but it did not work well in my tries. following is my test code.

#1st try
import webbrowser
url = 'www.google.com'
webbrowser.open(url, new=0) # this open new explorer window.

#....wait

#2nd try
webbrowser.open(url, new=0) # this open new explorer window again.

In my test, I test 2nd argument from 0 to 2, but there seems no change.
always opens new tab.

Is there any way to change address and open in the current opened browser window?

best Regards,
Tommy
msg312713 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-02-24 13:46
Hi Tommy,

The documentation states "If new is 0, the url is opened in the same browser window if possible."  It seems to be browser dependent, hence the 'if possible' caveat.  What operating system and browser are you using?
msg312715 - (view) Author: TitanSnow (tttnns) * Date: 2018-02-24 14:06
Hi Cheryl,

I think you may misunderstand.
What it means is to open URL in
the *same tab*, not *same window*,
which is not described in documentation.

Hi Tommy,

It’s hard to say what is “the same tab”.
Is it the current tab or the tab opened by
last webbrowser.open call?
If the user open a new tab in the opened browser,
then which tab is “the same tab”?
msg312717 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-02-24 14:15
TitanSnow, 

You're right, sorry about the confusion.

But, nevertheless, this does seem to be something that the browsers don't have available as an option.

Here's the Mozilla command line option page:
https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options

Under the Browser section, there is a note stating:
Note: When opening multiple URLs, Firefox always opens them as tabs in a new window.

I believe the other browsers behave the same.
msg312720 - (view) Author: TitanSnow (tttnns) * Date: 2018-02-24 14:25
Yes, I think so.

Maybe, in a web application, to achieve this,
the way is to use a GUI library then use its
web view widget.
msg312740 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-02-24 18:27
I'm going to close this as third party since it's browser and not Python related.
History
Date User Action Args
2022-04-11 14:58:58adminsetgithub: 77111
2018-02-24 18:27:14cheryl.sabellasetstatus: open -> closed
resolution: third party
messages: + msg312740

stage: resolved
2018-02-24 14:25:35tttnnssetmessages: + msg312720
2018-02-24 14:15:13cheryl.sabellasetmessages: + msg312717
2018-02-24 14:06:54tttnnssetnosy: + tttnns
messages: + msg312715
2018-02-24 13:46:35cheryl.sabellasetnosy: + cheryl.sabella
messages: + msg312713
2018-02-24 02:20:13tommylim1018@naver.comsetnosy: + ned.deily, ronaldoussoren
components: + Library (Lib), macOS
2018-02-24 02:17:13tommylim1018@naver.comcreate