javascript - 使用 jquery 重定向和打印页面加载

标签 javascript jquery

我想重定向(window.location 或 window.replace)到新的 url,并在加载该页面时希望使用 jquery 打印该页面 (.print())。

我已经尝试过

  window.location.replace(url).print();

但它只是重定向页面并且不打印页面, 有什么想法吗?

最佳答案

print() 添加到您要打印的站点的 onload 函数中。

 window.location.replace(url)

直接重定向到站点。所以 print() 永远不会被调用。

如果这不可能,您可以使用以下代码:

function printExternal(url) {
    var printWindow = window.open( url, 'Print', 'left=200, top=200, width=950, height=500, toolbar=0, resizable=0');
    printWindow.addEventListener('load', function(){
        printWindow.print();
        printWindow.close();
    }, true);
}

关于javascript - 使用 jquery 重定向和打印页面加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42175257/

相关文章:

javascript - 如何使用 JQuery 将动态创建的表中的值传递到新的数据库查询中?

javascript - 尝试在 angular2 中使用 stomp.js

javascript - D3 树状图调用产生 NaN x0、x1、y0、y1 值

javascript - 解决点击操作按钮冲突的可能方法

javascript - jQuery 的 offset() 在 "elem.getClientRects is not a function"处崩溃

javascript - jQuery 相当于 "getElementsByName"

javascript - 4.5.12 vue-cli 需要 vue@2.6.12 吗?

javascript - 无法使用 JQuery 更改 Span 文本

javascript - 将 html 数据从 angularjs 发布到 PHP

javascript - 从 gdata.youtube.com/feeds/api/videos (YouTube api) 获取 YouTube videoID