Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-13-2009, 05:37 PM   PM User | #1
Dark_Shadow
New to the CF scene

 
Join Date: Dec 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Dark_Shadow is an unknown quantity at this point
Problem with close()

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!

Code:
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>");
}

Last edited by Dark_Shadow; 12-13-2009 at 07:59 PM.. Reason: Problem solved! =)
Dark_Shadow is offline   Reply With Quote
Old 12-13-2009, 06:02 PM   PM User | #2
gusblake
Regular Coder

 
Join Date: Jan 2006
Posts: 568
Thanks: 6
Thanked 84 Times in 84 Posts
gusblake is on a distinguished road
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.

Last edited by gusblake; 12-13-2009 at 06:06 PM..
gusblake is offline   Reply With Quote
Old 12-13-2009, 07:14 PM   PM User | #3
Dark_Shadow
New to the CF scene

 
Join Date: Dec 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Dark_Shadow is an unknown quantity at this point
I tried it but it didn't work though. =/
Dark_Shadow is offline   Reply With Quote
Old 12-13-2009, 07:17 PM   PM User | #4
gusblake
Regular Coder

 
Join Date: Jan 2006
Posts: 568
Thanks: 6
Thanked 84 Times in 84 Posts
gusblake is on a distinguished road
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?
gusblake is offline   Reply With Quote
Old 12-13-2009, 07:36 PM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,032
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by gusblake View Post
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()'>");

Last edited by Philip M; 12-13-2009 at 07:49 PM..
Philip M is offline   Reply With Quote
Old 12-13-2009, 07:58 PM   PM User | #6
Dark_Shadow
New to the CF scene

 
Join Date: Dec 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Dark_Shadow is an unknown quantity at this point
Quote:
Originally Posted by gusblake View Post
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!

Quote:
Originally Posted by Philip M View Post
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
Dark_Shadow is offline   Reply With Quote
Reply

Bookmarks

Tags
close()

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:46 AM.


Advertisement
Log in to turn off these ads.