Forum Moderators: open
I need to generate a button on the fly that will open print window when user hits preview button on the previous page. Here is what i have so far:
elem = document.createElement("input");
elem.setAttribute("id", "btnPrint");
elem.setAttribute("value", "print document");
elem.setAttribute("alt", "print document");
elem.setAttribute("type", "button");
elem.setAttribute("onClick", "window.print()");
document.getElementsByTagName("body")[0].appendChild(elem);
What I would like to solve are two things: that button would *actually* appear on the newly created page and that it would be on top of the document (i guees i just call the function before any other body elements render). Any suggestions on how to make this button? Thanks in advance for reply.
to make button on top of the text you should use css styles like zIndex or make style - position:absoulte
on the top of this page in the current location
good luck to you
Thanks for reply. Button is created on fly with no problem now the thing is how to set onclick event to the newly created element
elem = document.createElement("input");
elem.id ='btnGumb';
elem.value = 'x close';
elem.type = 'button';
elem.onclick = window.close();
document.body.appendChild(elem);
i donno how to set onclick event in another meaningful way so that created button will respond to it. any thoughts? thanks.