导航到另一个页面并打印该页面?

时间:2014-03-28 10:18:51

标签: javascript php jquery html

我有一个php脚本(process.php),我在其中执行所有操作并生成这样的html输出。

PROCESS.PHP

<?php
   ob_start();
   //Rest of my php code is here.
   echo "FINAL";
   file_put_contents('record.html', ob_get_contents());
   ob_end_flush();
   //it will write a file named 'record.html' in the same directory.
?>

现在我想要的是当任何用户打开这个process.php文件时,他将被重定向到record.html并自动显示打印选项。

无论用户是打印文档还是取消/关闭打印选项,页面都应自动关闭。

2 个答案:

答案 0 :(得分:0)

此代码将满足您的要求,但效率不是100%。但是你可以用它来做你的工作。

setTimeout(function(){var ww = window.open(window.location, '_self'); 
ww.close()},100); 
window.print();

如果对代码有任何疑问,可以询问。感谢

答案 1 :(得分:0)

有很多方法可以做到这一点你可以使用javascript window.print加载这个页面进行打印然后你可以使用window.location.href =“link”打开这个打印页面之前的链接。任何年龄,不包括此打印页面“或者如果您想使用window.open(),您可以将此年龄打开到另一个窗口。 试试这个。

window.print(); window.location.href =“另一个年龄”; //或window.close()完全关闭窗口
相关问题