Posted on Thursday, November 19, 2009 at 9:15 PM
Here is an example of how to add a button to a page at a specific location and then have it call a function onclick.
// Inserts javascript that will be called by the autoCheckOrderButton
var scriptElement = document.createElement('script');
scriptElement.type = 'text/javascript';
scriptElement.innerHTML = 'function checkForOrders() { alert("inside checkForOrders"); }';
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('offer');
// 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 = 'Start Checkin';
inputButton.setAttribute("onclick", "checkForOrders();");...