从Edge打开PDF而不打开多余的空白标签 [英] Open a PDF from Edge without opening redundant blank tabs

查看:706
本文介绍了从Edge打开PDF而不打开多余的空白标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理的页面列出了文档.每个文档都是可单击的链接.单击可打开一个PDF(取决于用户的设置,该PDF通常会在一个不同的选项卡,甚至是一个不同的应用程序中打开),然后重新加载原始选项卡,以便更新页面上的未读"计数,并将链接样式更改为表示已读".

The page I'm working on lists documents. Each document is a clickable link. Clicking opens a PDF (which typically opens in a different tab, or even a different application, depending on the user's settings), then reloads the original tab so that an "unread" count on the page is updated and the link style is changed to indicate "read".

围绕文档详细信息的HTML范围:

HTML span surrounding the document details:

<span class='btn-link' onclick='openReport(@orderNumber, @tableBodyId); return false;'>

JavaScript:

Javascript:

function openReport(orderNumber, tableBodyId) {
    var url = "/Reports/ValuationReportDocPdf?orderNumber=" + orderNumber;
    var win = window.open(url, '');
    setTimeout(function () { location.reload(); }, 3000);
}

JavaScript可以在Chrome,Firefox和IE11中正常工作.

The Javascript works as intended in Chrome, Firefox and IE11.

在Edge中,单击链接时,空白选项卡将打开并获得焦点,而原始选项卡在选项卡栏上闪烁,等待我在保存",另存为"和取消"之间进行选择.因此,用户必须返回到原始选项卡才能继续.首先,这是一个非常混乱的用户体验.然后,如果单击保存",情况会变得更糟:打开了包含PDF的第三个标签.

In Edge, when the link is clicked, a blank tab is opened and receives focus while the original tab is blinking on the tab bar, waiting for me to choose between "Save", "Save As" and "Cancel". So the user must go back to the original tab to proceed. That's quite a messy user experience to start with. Then, if I click "Save", it gets worse: a third tab is opened containing the PDF.

问题

如何让Edge玩得更好?我希望焦点一直停留在原始页面上,直到用户选择要处理的PDF,然后在不打开任何空白标签的情况下打开PDF.

How do I get Edge to play nicely? I want focus to stay on the original page until the user has chosen what to do with the PDF, then open the PDF without opening any empty tabs.

修改

This post seems related, but it uses an <a>. I don't think I can use an anchor because I need to also refresh the page.

推荐答案

我发现仅边缘,我动态创建一个具有download属性的<a>,然后单击它.

I found some help with this one. For Edge only, I dynamically create an <a> with a download attribute, and "click" it.

function openReport(orderNumber, tableBodyId) {
    var url = "/Reports/ValuationReportDocPdf?orderNumber=" + orderNumber;

    if (isEDGE()) {
        var dl = document.createElement('a');
        dl.setAttribute('href', url);
        dl.setAttribute('download', 'filename.txt');
        dl.click();
    } else {
        window.open(url, '');
    }

    setTimeout(function () { location.reload(); }, 3000);
}

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

这篇关于从Edge打开PDF而不打开多余的空白标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆