ron123456
ron123456

Reputation: 153

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.

Upvotes: 3

Views: 1609

Answers (1)

Davide Andrea
Davide Andrea

Reputation: 1413

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'

Upvotes: 1

Related Questions