Open HTML file in same tab using python script

感情迁移 提交于 2019-12-12 13:05:09

问题


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.


回答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'


来源:https://stackoverflow.com/questions/51206588/open-html-file-in-same-tab-using-python-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!