2016-08-02 95 views
0

我有我的PHP变量中的HTML说$ html,我想用javascript打印此html。我为此写了下面的代码。使用PHP变量和javascript打印HTML

<script>var mywindow = window.open('', 'my div', 'height=400,width=600'); 
    mywindow.document.write(<?= $html ?>); 
    mywindow.print();</script> 

它为我,如果变量包含正常的字符串不HTML

+0

你的代码没有错误。我个人现在跑它,它的工作原理。 –

回答

2

尝试写功能就像使用引号,

mywindow.document.write("<?= $html ?>"); 
+0

所有的代码都在php文件中,它就像mywindow.document.write($ html); –

+0

如果html在另一个页面上,那么你可以设置'$ _SESSION ['html']',然后打印后你可以取消设置。 –

0

您需要昏迷:

mywindow.document.write('<?= $html ?>');