次の目的でグリースモンキー スクリプトを作成しました。
- サードパーティの 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();