新窗口位置更改的打印结果

时间:2019-06-24 17:37:11

标签: javascript firefox printing safari

我想创建一个新窗口,该窗口的URL由获取/ ajax请求异步获取,并直接显示其打印对话框,而不会出现弹出错误。

我的代码如下:

onSubmit(e) {
    e.preventDefault();

    // Need to create window here because inside the result you would get a popup error
    const newWindow = window.open('', '_blank');

    fetch('/my-api')
        .then(result => result.json())
        .then((result) => {
            newWindow.location.href = result.pdfUrl; // http://example.org/my-test.pdf 
            newWindow.print(); // this seems to print blank page because the pdf is not yet loaded?
        })
    ;
}

我尝试的解决方案仅在台式机上的Chrome上有效,而在Firefox或Safari上无效。

0 个答案:

没有答案