...

View Full Version : Resolved Problem with close()



Dark_Shadow
12-13-2009, 06:37 PM
Hi! I have a problem with the function close();

The window does open but then it immediately closes by itself. I didn't even get to see the content and of course I didn't even click on the button "close the window!"

I want to be able to see the content of the page and when I click on the button, it will close the window. Thank you in advance for your help!



var window;
function newWindow(){
window=window.open("", "Results", "width=400, height=250");
window.document.write("<body><table>");
window.document.write("<h1 style='border-bottom-style: dotted; border-bottom-width: 1px;font: italic 16pt Times New Roman, sans-serif; color: navy;'>Survey's Results</h1>");
for(var i=0; i<tabVotes.length; i++){
window.document.writeln("<tr>");
window.document.writeln("<td style='text-align: center'>" + tabPeople[i] + "</td>");
window.document.writeln("<td style='text-align: center'>" + tabVotes[i] + " votes </td>");
window.document.writeln("</tr>");
}
window.document.writeln("</table>");
window.document.writeln("<input name='Close' type='button' value='Close the window' />");
window.document.getElementById('Close').onclick = window.close();
window.document.writeln("<br /><br />Thank you!");
window.document.writeln("</body>");
}

gusblake
12-13-2009, 07:02 PM
Try putting window.close() in quotes.

Also, I don't think the name attribute is picked up by getElementById, so you will need to give the button id="Close" to get it to work.

Dark_Shadow
12-13-2009, 08:14 PM
I tried it but it didn't work though. =/

gusblake
12-13-2009, 08:17 PM
Just to rule out any possible conflict it would be a good idea not to use 'window' as a handle for the popup.

What's not working about it?

Philip M
12-13-2009, 08:36 PM
Just to rule out any possible conflict it would be a good idea not to use 'window' as a handle for the popup.



Agreed! That is the problem. :(
I don't see how window=window.open("", "Results", "width=400, height=250"); could ever have worked.

Try this (I have changed window to popWin):-

popWin.document.writeln("<input type='button' value='Close the window' onclick = 'window.close()'>");

Dark_Shadow
12-13-2009, 08:58 PM
Just to rule out any possible conflict it would be a good idea not to use 'window' as a handle for the popup.

What's not working about it?

I was referring to your previous comment "Try putting window.close() in quotes. Also, I don't think the name attribute is picked up by getElementById, so you will need to give the button id="Close" to get it to work."

Thank you for trying to help me!


Agreed! That is the problem. :(
I don't see how window=window.open("", "Results", "width=400, height=250"); could ever have worked.

Try this (I have changed window to popWin):-

popWin.document.writeln("<input type='button' value='Close the window' onclick = 'window.close()'>");

Thank you so much! It's working now!!! I am finally done with my assignment. =D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum