Reputation: 95
i have a.html which is
a.html
<script>
function printContent(el){
var restorepage = document.body.innerHTML;
var printcontent = document.getElementById(el).innerHTML;
document.body.innerHTML = printcontent;
window.print();
document.body.innerHTML = restorepage;
}
</script>
<div id="div1">DIV 1 content...</div>
<button onclick="printContent('div1')">Print Content</button>
i want to print contain in a.html which the button is in b.html
b.html
<a href="#" onclick="printContent("printJS")">Print</a>
How to pass the func to other file?
thanks
Upvotes: 0
Views: 348
Reputation: 144
Extract your function to separate *.js file and include this file in both html files.
<script src="myscripts.js"></script>
Upvotes: 2