How to prevent a blank tab from appearing in Edge when clicking on a file link

百般思念 提交于 2019-12-02 07:26:47
er-han

I don't think there is anything you can prevent Edge's this behaviour. What you can do is to change the HTML tag.

Use download attribute in <a> element without target attribute. This way, the browser will prompt save dialog instead of opening a new tab.

<a href="myfile" download>Download</a>

http://www.w3schools.com/tags/att_a_download.asp

In this case, the browser will not display the file inline.

If you still want your clients be able to see the files inline you can detect the client's browser; if it is Edge then use the download attribute, if not use target attribute. In addition, you can use something like navigator.mimetypes to detect which file types can be displayed inline (see https://developer.mozilla.org/en-US/docs/Web/API/NavigatorPlugins/mimeTypes).

Here is the detect function which I took from another post (How can I detect Internet Explorer (IE) and Microsoft Edge using JavaScript?)

function isEDGE(){
 return /Edge\/\d./i.test(navigator.userAgent)
}

Leave your <a> tags with no target and download attributes. Use detect function and decide on the right attribute.

Like this:

$(document).ready(function(){
    if(isEDGE()) {
        $('a').attr('download','download');
    } else {
        $('a').attr('target','_blank');
    }
})

Note: I am not sure about Edge detecting function.

Method 1: I suggest you clear the Clear browsing data option of Microsoft Edge and check if you face the issue. To do so perform the steps below. Click on the More actions icon next to the feedback icon present on top right corner of the Edge. Select Settings and click on Choose what to clear. Check the boxes Browsing history, Cookies and saved website data and Cached data and files and click on Clear.

Method 2: If you are using any Proxy connection, then try disabling the proxy connection and check. Follow the steps to disable proxy: Click the Settings icon at the top right corner in internet explorer. Click the Tools button, and then click Internet Options. Click the Connections tab, and then click LAN settings. Uncheck the box next to “proxy server for your LAN”. Click on OK to save the setting and close window. Now check the issue by opening Edge.

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