如何从Internet Explorer无缝重定向到Microsoft Edge?

问题描述

我正试图在我的网站上弃用Internet Explorer,并且我想在有人尝试在Internet Explorer上访问Twitter时复制Twitter的行为。

从到目前为止我完成的工作来看,似乎有一个基于用户代理字符串的服务器端检查,它检测浏览器类型,然后发送一些内容重定向到https://go.microsoft.com/fwlink/?linkid=2135547,但同时打开Microsoft Edge并将其定向到https://twitter.com

对我来说,令人困惑的部分是他们如何在不打开询问您是否要打开与应用程序链接的对话框的情况下打开Microsoft Edge。我见过网站使用microsoft-edge:url在Microsoft Edge中打开URL,但这总是询问您是否要打开该应用程序。

如果有人知道如何管理或复制它的信息,将不胜感激。

如果有帮助,我的网站是基于express.js构建的,而我正在尝试的重定向基于某些快速中间件中的res.redirect

解决方法

这似乎是Internet Explorer和Edge之间的特殊接口,它使用名为“ IEtoEdge BHO”的Internet Explorer浏览器帮助器对象以及Microsoft维护的不兼容网站的列表。

这需要Microsoft Edge稳定版87或更高版本。

https://docs.microsoft.com/en-us/deployedge/edge-learnmore-neededge

以下代码与行为极为相似,但Edge中的对话框除外,以迁移浏览数据和首选项。我没有收到任何提示,所以可能已经改变了。

<script>
  if(/MSIE \d|Trident.*rv:/.test(navigator.userAgent)) {
    window.location = 'microsoft-edge:' + window.location;
    setTimeout(function() {
      window.location = 'https://go.microsoft.com/fwlink/?linkid=2135547';
    },1);
  }
</script>
,

当我尝试在IE 11浏览器中访问Twitter时,页面上将显示以下消息。它没有重定向到任何Microsoft页面,也没有在Edge浏览器中启动Twitter页面。

enter image description here

因此,我不确定您如何在计算机上获得此行为。

我看到您希望避免出现弹出窗口,该弹出窗口要求用户允许网站在Edge浏览器中打开。

我没有任何可以抑制该弹出窗口的设置。我建议尝试使用可识别浏览器并显示链接的JS代码,以便在Edge浏览器中打开网站。如果用户单击链接,则不会显示弹出窗口和Edge浏览器将直接启动。

示例代码:

<!doctype html>
<html>
    <head>
        <script>
            function FindIE() {
  
              var ua = window.navigator.userAgent;
              var msie = ua.indexOf("MSIE ");
  
              if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) 
              {     document.write("The Internet Explorer browser is not supported by this site. We suggest you visit the site using supported browsers." + "<A HREF='microsoft-edge:http://<<Your site address..........>>'>Click here to launch the site in the MS Edge browser</A>");
                  
              }
              else  
              {
                document.write("Welcome...");
              }
  
              return false;
              }
              FindIE()
        </script>
    </head>
    <body>
             
    </body>
</html>

在IE 11浏览器中的输出:

enter image description here

此外,您可以尝试修改代码以使其与express.js一起使用

,

虽然 Molanda 和 Deepak-MSFT 的答案有效。 Molanda 的回答会将 Windows 8.1、2016、2019 用户重定向到一个页面,告诉他们使用他们没有的浏览器。 Deepak-MSFT 要求用户点击链接。

感谢 navigator.msLaunchUri,您可以响应对 microsoft-edge 的支持。请注意,如果您仍然关心它,这在 Windows 7 中将不起作用。

if (typeof (navigator.msLaunchUri) === "function") {
  navigator.msLaunchUri('microsoft-edge:' + window.location.href,function () { window.location.href="https://go.microsoft.com/fwlink/?linkid=2151617" },function () {console.log('ie but no edge')}
  )
}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...