I have created a greasemonkey script for the purpose of:
- Add print receipt button to 3rd party web app page
- Add receipt printer friendly styles to div in new window
- print this window
The button shows up, but it doesn’t trigger my function, which at this point just prints the div.
Here’s where I’m at:
var scriptElement = document.createElement('script');
scriptElement.type = 'text/javascript';
scriptElement.innerHTML = 'function printReceipt() { \
var divToPrint=document.getEelementById("loanTable"); \
newWin= window.open(""); \
newWin.document.write(divToPrint.outerHTML); \
newWin.print(); \
newWin.close(); \
}';
document.getElementsByTagName("head")[0].appendChild(scriptElement);
window.addButton = function () {
// Get the location on the page where you want to create the button
var targetDiv = document.getElementById('newcheckout');
// Create a div to surround the button
var newDiv = document.createElement('div');
newDiv.setAttribute('id', 'autoCheckOrder');
// Create the button and set its attributes
var inputButton = document.createElement('input');
inputButton.name = 'autoCheckOrderButton';
inputButton.type = 'button';
inputButton.value = 'Print Receipt?';
inputButton.setAttribute("onclick", "printReceipt();");
// Append the button to the div
newDiv.appendChild(inputButton);
targetDiv.appendChild(newDiv);
}
addButton();
There is a typo on this line:
Change it to:
Alternately, add this line to your script’s metadata section:
Then the whole script becomes: