Reputation: 77
function close_w() {
//close the window
}
function imgopen(image) {
var newWindow=window.open("", "_blank", "width=450, height=400");
var newButton=newWindow.document.createElement("button");
var textNode=newWindow.document.createTextNode("Close");
newButton.setAttribute("style", "text-align: center; width: 30%; height: 30px; margin-top: 10px; margin-left: 35%; border: none; color: #FFF; background-color: #DC143C");
newButton.setAttribute("onclick", "close_w()");
newWindow.document.newButton.appendChild(textNode); // Line Marker
newWindow.document.body.appendChild(newButton);
}
I want to put a button in a popup, but appending textNode to newButton does not work and even the button does not show. If I delete the line marked, only the button shows.
And I also want to make the popup close when the button is clicked, but I cannot imagine how to do that. What functions can I use to make close_W()?
This is a kind of assignment: I cannot use jQuery here.
I am weak at JS. Please help!
Upvotes: 0
Views: 26
Reputation: 1037
Like other buttons, you need to set the value of newButton
to get the text added to it. Something like newButton.setAttribute("value", "Close Window");
. This example would be for a button in an input
. If you were to use the <button></button>
tag, I would suggest you use newButton.innerHTML = "Close Window";
as that should set the text to "Close Window".
Upvotes: 1