在Chrome上(我到目前为止只尝试过此操作)我可以打开一个空窗口,写一行并自动打印页面:
<script type="text/javascript">
function openWin()
{
var win = window.open('','','width=600,height=600');
win.document.write("Write a line here!");
win.document.close();
win.focus();
setTimeout( function () {
win.print();
win.close();
}, 1000 );
}
</script>
...
<input type="button" value="Open window" onclick="openWin()" />
但是我无法打开网址并自动打印页面:
<script type="text/javascript">
function openWin()
{
var win = window.open('http://google.it','','width=600,height=600');
win.document.close();
win.focus();
setTimeout( function () {
win.print();
win.close();
}, 1000 );
}
</script>
...
<input type="button" value="Open window" onclick="openWin()" />
这可能吗? Chrome有一些限制吗?