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.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With