I need to create a button whose function is to scroll to the top of the page and then print it.
My code attached to the button is the following:
<script>
jQuery(document).ready(
function($){
$('#backToTop').click(function(){
$("html, body").animate({ scrollTop: 0 }, 500, function() {
window.print();
});
});
}
);
</script>
And the button
<a id="backToTop">Print</a>
but the print method runs twice. I can't find a solution to prevent printing from running twice.
How can this be fixed?