edge打开pdf不显示印章_从Edge打开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 span surrounding the document details:

Javascript:

function openReport(orderNumber, tableBodyId) {

var url = "/Reports/ValuationReportDocPdf?orderNumber=" + orderNumber;

var win = window.open(url, '');

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

}

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

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.

Question

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.

Edit

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

解决方案

I found some help with this one. For Edge only, I dynamically create an 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);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值