我创建了一个greasemonkey脚本,目的是:
- 将打印收据按钮添加到 3rd 方 Web 应用程序页面
- 在新窗口中将收据打印机友好样式添加到 div
- 打印此窗口
按钮出现了,但它不会触发我的函数,此时它只是打印 div。
这是我所在的位置:
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();