JimPapas JimPapas - 4 months ago 12
PHP Question

PHP : not return to sender page after clicking a button to print

I have a PHP page that shows some search results.
At the end i put a form with a button to print the content of this page.
With microsoft Edge (not tested with internet explorer), after the printig (or cancel printing) this page is shown again and i can refine results and print again etc
With Chrom, after clicking the print button and before the printing form show up, the sender page changes to the site's home page.
Why ? and how can force the page to stay, please ?
below is the code i use

</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>

Answer

change the onclick event:

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

The "return false" is inserted to stop the default action, which is to follow the link.

Comments