Skip to main content
 首页 » 编程设计

python之单击链接时使用python打开IE浏览器窗口

2024年12月31日8softidea

我需要一个专门在IE浏览器中打开的url。 我知道下面的代码是错误的,但我不知道还能尝试什么。 我怎样才能通过 python 实现它?

模板

<a href="{% url 'browser:ie' %}" target="_blank"> Open in IE </a> 

urls.py

url(r'^open-ie$', views.open_in_ie, name='ie'), 

views.py

import webbrowser 
def open_in_ie(request): 
    ie = webbrowser.get(webbrowser.iexplore) 
    return ie.open('https://some-link.com') 

同样,我知道这是错误的,它会尝试在服务器级别打开 ie 浏览器。有什么建议吗?谢谢!

请您参考如下方法:

射击答案:你不能。
长答案:如果用户使用 IE 查看您的网站,您可以在其他浏览器中打开链接。但如果用户使用任何其他浏览器(firefox、chrome 等),所有链接都将在同一浏览器中打开,您无法访问其他浏览器。所以在你的情况下答案是否定的,因为你正试图从其他浏览器打开 IE。
如果您有兴趣,这里是从 IE 打开另一个浏览器的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html lang="en"> 
<head> 
    <title>HTA Test</title> 
    <hta:application applicationname="HTA Test" scroll="yes" singleinstance="yes"> 
    <script type="text/javascript"> 
        function openURL() 
        { 
            var shell = new ActiveXObject("WScript.Shell"); 
            shell.run("http://www.google.com"); 
        } 
    </script> 
</head> 
<body> 
 
    <input type="button" onclick="openURL()" value="Open Google"> 
 
</body> 
</html> 

Code from here