LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-06-2005, 12:47 PM   #1
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Rep: Reputation: 30
Javasript - closing a window


i am having a problem closing a window in javascript.

first when a user clicks a button i dynamically create a window, but i want to add a button on the newly created window so when a user clicks the button it will close the new window.

for example
Code:
/*creates a new window */
newWin = window.open("","", "toolbar=yes,width=650,height=600,resizable=yes");
newWin.document.write(  /*html code goes here */ );
so i want to create a button on newWin object so when a users clicks it, it will close.
i've tried
Code:
/*creates a button */
newWin.document.write("<input type='button' value='Close'>");
if(newWin.document.captureEvents(Event.Onclick)) {
                newWin.close();
}
but that doesn't work, is there way to add listeners in javascript so when a user clicks a button it will close.

thanks for you help

djgerbavor3
 
Old 05-06-2005, 01:01 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Try this code :
Code:
<script>
function openWin() {
    newWin = window.open("","", "toolbar=yes,width=650,height=600,resizable=yes");
    var closebutton = newWin.document.createElement("input");
    closebutton.setAttribute("type", "button");
    closebutton.setAttribute("value", "Close this window");
    closebutton.setAttribute("onclick", "window.close()");
    newWin.document.body.appendChild( closebutton );
}
</script>

<input type="button" value="Open a window" onclick="openWin()">
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
opening/closing window sounds matt_com911 Fedora 1 06-18-2005 09:17 PM
closing a frozen window!? ungua Linux - Software 6 11-14-2004 01:38 PM
Close window error when not closing firehawk573 Programming 0 03-22-2004 03:05 PM
How to re-open kppp after closing window carjumble Linux - Newbie 2 12-24-2003 08:20 PM
X-Window Freeze when closing X Session smitchel Linux - Software 3 11-12-2001 11:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration