469,926 Members | 1,497 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

How to close opened popup window by clicking a button?

Hello all,

Help me!

--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script language="JavaScript">
<!--
function popMe() {
openMe = window.open('http://www.google.com/','google','location=no,
status=no, width=640, height=480, left=100, top=100');
openMe.focus();
}

function closeOpened() {
closeIt = window.close('google'); // I need help on this line.
}
//-->
</script>

</head>

<body>

<input type="button" value="Click me!" onclick="popMe();" /> <input
type="button" value="Close opened" onclick="closeOpened();" />

</body>
</html>
--------------------

I have one button says "Click me!" when I click on that button its
calls a function "popMe()" and opens a popup window. And also I have
another button which says "Close Opened" and when I click on it, it
doesn't close the opened window.

Is my script is wrong? Help me on the function "closeOpened()".

Thank you in adv.

-----
Sujan

Jul 23 '05 #1
6 12568
Sujan wrote:
function popMe() {
openMe = window.open('http://www.google.com/','google','location=no,
status=no, width=640, height=480, left=100, top=100');
openMe.focus();
}

function closeOpened() {
closeIt = window.close('google'); // I need help on this line.
}


You must call the close method of your opened window, not from your
current one:

if (openMe && openMe.close && !openMe.closed)
openMe.close();

Daniel
Jul 23 '05 #2
Thanks.

It worked, but there's a problem. When i click on "Close Opened"
without opening a popup, it says error on page 'openMe' is undefined.

Can I alert the user when they click first "Close Opened" button
without opening popup.

I'll be Thankful.

-----
Sujan

Jul 23 '05 #3
"Sujan" <su*****@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hello all,

Help me!

--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script language="JavaScript">
<!--
function popMe() {
openMe = window.open('http://www.google.com/','google','location=no,
status=no, width=640, height=480, left=100, top=100');
openMe.focus();
}

function closeOpened() {
closeIt = window.close('google'); // I need help on this line.
}
//-->
</script>

</head>

<body>

<input type="button" value="Click me!" onclick="popMe();" /> <input
type="button" value="Close opened" onclick="closeOpened();" />

</body>
</html>
--------------------

I have one button says "Click me!" when I click on that button its
calls a function "popMe()" and opens a popup window. And also I have
another button which says "Close Opened" and when I click on it, it
doesn't close the opened window.

Is my script is wrong? Help me on the function "closeOpened()".

Thank you in adv.

-----
Sujan


Will this help? Watch for word-wrap.

<html>
<head>
<title>closer.html</title>
<script type="text/javascript">
var pop;
function popOpen() {
pop = window.open('http://www.google.com/','google','status=no,width=640,
height=480,left=100,top=100');
}
</script>
</head>
<body>
<form>
<input type="button" value="Click me!" onclick="popOpen();" />
<input type="button" value="Close it!" onclick="pop.close()" />
</form>
</body>
</html>
Of course, you can still have:

function popClose() {
pop.close();
}

<input type="button" value="Close it!" onclick="popClose()" />
Jul 23 '05 #4
Sujan wrote:
It worked, but there's a problem. When i click on "Close Opened"
without opening a popup, it says error on page 'openMe' is undefined.
You need to either check the existence of your global variable first or
define one before.

Can I alert the user when they click first "Close Opened" button
without opening popup.


if (typeof openMe == "object" && openMe.close && !openMe.closed)
openMe.close();
else
alert("No window open");

Daniel
Jul 23 '05 #5
Thank you ppls, now it works better.

-----
Sujan

Jul 23 '05 #6
Thank you ppls, now it works better.

-----
Sujan

Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Temp | last post: by
2 posts views Thread by David W. Simmonds | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.