使用python脚本在同一选项卡中打开HTML文件 [英] Open HTML file in same tab using python script
本文介绍了使用python脚本在同一选项卡中打开HTML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用python脚本打开HTML页面.使用以下脚本,文件将在新的浏览器选项卡中打开.我应该如何在同一标签中打开它?
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'))
我尝试添加
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.
推荐答案
恐怕您需要通过Javascript来实现:
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'
这篇关于使用python脚本在同一选项卡中打开HTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文