3

I am trying to open a HTML page using python script. With the following script the file opens in a new browser tab. How should I make it open in the same tab?

import webbrowser
import os
import urllib

chrome_path="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
webbrowser.register('chrome', None,webbrowser.BackgroundBrowser(chrome_path))
webbrowser.get('chrome').open(os.path.realpath('image.html'))

EDIT 1:

I tried adding

webbrowser.get('chrome').open(os.path.realpath('image.html'), new=1, autoraise=True)

it opens in the same browser but not in the same tab.

4
  • in python docs : docs.python.org/2/library/webbrowser.html. I see webbrowser.open(url, new=0, autoraise=True) Display url using the default browser. If new is 0, the url is opened in the same browser window if possible Commented Jul 6, 2018 at 9:23
  • yes, I found that. And it opens in the same browser. But it opens always in a new tab. Is there any way to restrict it from opening in new tab Commented Jul 6, 2018 at 9:32
  • one answer comes from firefox :support.mozilla.org/fr/questions/970999. Try it with chrome Commented Jul 6, 2018 at 9:44
  • 1
    Ty @Pain for your effort. Really appreciate it. Commented Jul 6, 2018 at 10:04

1 Answer 1

1

I am afraid you need to do it through Javascript:

RefreshTab = '<script language="JavaScript" type="text/JavaScript">window.location = \'%s\';</script>'
print RefreshTab % 'yourscript.py'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.