Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open HTML file in same tab using python script

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.

like image 846
ron123456 Avatar asked May 09 '26 08:05

ron123456


1 Answers

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'
like image 157
Davide Andrea Avatar answered May 10 '26 22:05

Davide Andrea



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!