Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing window using onClick="function()" 1

Status
Not open for further replies.

gns100

Programmer
Aug 11, 2003
40
US
The code below opens a window and creates a close button.
I can get the window to close by using <button onClick=&quot;window.close()&quot;> but I want to do this using the function closeWindow() as shown.

What am I missing here? It should be fairly simple.
Thanks,

Code:
<html>

<head>
<title>New Page 1</title>
</head>

<body>

<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>

function closeWindows(){
    window.close();
    //jkpopwin.window.close()
}


popwidth=400;
popheight=450;
leftpos1=420;
toppos=210;
popbackground=&quot;orange&quot;;
textdescription=&quot;TEXT HERE&quot;;
var winattributes='width='+popwidth+',height='+popheight+',resizable=no,left='+leftpos1+',top='+toppos
var bodyattribute=(popbackground.indexOf(&quot;.&quot;)!=-1)? 'background=&quot;'+popbackground+'&quot;' : 'bgcolor=&quot;'+popbackground+'&quot;'
if (typeof jkpopwin==&quot;undefined&quot; || jkpopwin.closed)
jkpopwin=window.open(&quot;&quot;,&quot;&quot;,winattributes)
else{
//getpos() //uncomment these 2 lines if you wish subsequent popups to be centered too
//jkpopwin.moveTo(leftpos, toppos)
jkpopwin.resizeTo(popwidth, popheight+30)
}

jkpopwin.document.open()
jkpopwin.document.write('<html><title>test</title><head></head> <body '+bodyattribute+' ><center><br><br>'+textdescription+'<BR><BR>[b]<BUTTON onClick=&quot;closeWindow()&quot;>Close Window</BUTTON>[/b]</center></body></html>')
jkpopwin.document.close()
jkpopwin.focus()
</script>

</body>
</html>
 
This uses self.close() in a function cls();

(You can do view source on the pop-Up to see
how the script looks after it's written to the pop-up..)

Try changing your existing lines above to:

Code:
jkpopwin.document.open()
jkpopwin.document.write(&quot;<html><title>test</title><head>\n&quot;+
		&quot;<script language='Javascript'>\n function cls()\n \{self\.close()\}\n&quot;+
	&quot;<\/script><head>\n<body &quot;+bodyattribute+&quot;><center>\n<br><br>&quot;+textdescription+&quot;<BR><BR>&quot;+
		&quot;<BUTTON onClick='cls()'>Close Window</BUTTON></center></body></html>&quot;);
jkpopwin.document.close();
jkpopwin.focus();


2b||!2b
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top