Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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! =)

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried it but it didn't work though. =/

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    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?

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,986
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    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.

  • #6
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •