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.

ron123456
  • 153
  • 8
  • in python docs : https://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 – xPain Jul 06 '18 at 09: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 – ron123456 Jul 06 '18 at 09:32
  • one answer comes from firefox :https://support.mozilla.org/fr/questions/970999. Try it with chrome – xPain Jul 06 '18 at 09:44
  • 1
    Ty @Pain for your effort. Really appreciate it. – ron123456 Jul 06 '18 at 10:04

1 Answers1

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'
Davide Andrea
  • 1,357
  • 2
  • 15
  • 39