2016-07-06 44 views
1

我有一个显示一些搜索结果的PHP页面。 最后,我用一个按钮来打印这个页面的内容。PHP:单击按钮打印后不返回到发件人页面

使用microsoft Edge(未使用Internet Explorer进行测试),打印(或取消打印)后,该页面会再次显示,并且我可以优化结果并再次打印。 使用Chrome,点击打印按钮之后打印表单显示,发件人页面更改为网站的主页。 为什么?

我该如何强制页面留下来? 下面是我的代码使用

</script> 
    <script type="text/javascript"> 
    function printW() { 
    window.print(); 
    window.location.reload(); 
    } 
</script> 

<form name="footerForm" id="footerForm" > 
    <div class="example-screen"> 
     <table style="background-color:rgb(252,252,252)">   
      <tr> 
       <td> 
        <button onclick="printW();" id="myButton" class="float-left submit-button"><img src="http://......./Print.png" alt=""/> 
       </td> 

      </tr> 
     </table> 
    </div> 
</form> 

回答

1

变化onclick事件:

<button onclick="printW(); return false" id="myButton" class="float-left submit-button"><img src="http://......./Print.png" alt=""/> 

的“返回false”插入停止默认操作,它是遵循的链接。

+0

什么是一个快速正确的答案!非常感谢! – JimPapas

2

如果你只是想打印的页面,就没有必要用下面的命令来重新加载页面:

window.location.reload(); 

你也不必把内部形状的按钮,打印页面。由于表单,它会在点击一个按钮时提交。你可以把它没有这样的形式,

<div class="example-screen"> 
    <table style="background-color:rgb(252,252,252)">   
     <tr> 
      <td> 
       <button onclick="printW();" id="myButton" class="float-left submit-button"> 
        <img src="http://......./Print.png" alt=""/> 
       </button> 
      </td> 
     </tr> 
    </table> 
</div> 
+0

你是对的。非常感谢 – JimPapas

+0

从技术上讲,这是更好的答案。为什么要添加一个表单然后使用'return false'来停止执行。 –

相关问题