473,777 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="JavaS cript">
<!--
function popMe() {
openMe = window.open('ht tp://www.google.com/','google','loc ation=no,
status=no, width=640, height=480, left=100, top=100');
openMe.focus();
}

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

</head>

<body>

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

</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 12819
Sujan wrote:
function popMe() {
openMe = window.open('ht tp://www.google.com/','google','loc ation=no,
status=no, width=640, height=480, left=100, top=100');
openMe.focus();
}

function closeOpened() {
closeIt = window.close('g oogle'); // 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.goo glegroups.com.. .
Hello all,

Help me!

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

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

</head>

<body>

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

</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.h tml</title>
<script type="text/javascript">
var pop;
function popOpen() {
pop = window.open('ht tp://www.google.com/','google','sta tus=no,width=64 0,
height=480,left =100,top=100');
}
</script>
</head>
<body>
<form>
<input type="button" value="Click me!" onclick="popOpe n();" />
<input type="button" value="Close it!" onclick="pop.cl ose()" />
</form>
</body>
</html>
Of course, you can still have:

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

<input type="button" value="Close it!" onclick="popClo se()" />
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6962
by: dibyendu_k | last post by:
Hi, There is a problem i cant solve regarding Internet Explorer 5.5. It is regarding the Print Dialog Box. From a webpage if I open a popup window (window.open()) containing buttons Print and Close. The functionality is that when i press the "print" button the Print dialog box is opened (window.print();) and when I click on the close button the popup window is closed (window.close();) But the problem occurs when 1. The Print button is...
4
34888
by: GrantS | last post by:
I am having a problem closing a popup window opened modally. When I try to close the window (when the user hits save button and the data has been processed), the Popup window opens as a full screen as a new window. The original window plus the Modally opened Pop remain in a separate window. What I want to do is close the popup and return to the original window with its view state maintained. The control use to fire the popup window...
1
328
by: Temp | last post by:
Can anyone tell me how I can open a new browser window when a button is pressed? I tried adding an <a href=...> encapsulating the button, but it didnt work. Any suggestions? -- _____________________________ Ron Rodenberg
2
1592
by: David W. Simmonds | last post by:
I have a popup window appear when a user clicks on a hyperlink in a datalist. I do it like this: dr = "javascript:mywindow=window.open(" + "\"GameStats.aspx?Date="+dr + "&Away="+dr + "&Home="+dr + "\"" + ",\"GamesStats\",\"toolbar=no,location=no,directories=no,menubar=no,resizabl e=yes,scrollbars=yes,width=640,height=300\");mywindow.focus();"; dr is a DataRow item that is added to a DataTable that becomes the DataSource of the...
3
1670
by: Chrysan | last post by:
I have a popup window, which consist of a asp:textbox and a asp:button. And, I would like to pass the textbox.text to the javascript function when I click the button. Besides, by clicking the button, also close the popup window. The problem is, when I click the button, the textbox.text is successfully pass to the javascript function and the popup window will be closed, but the popup window will be opened again in maximize mode. I notice...
2
1037
by: coimbatoresivakumar | last post by:
hi friends i'm using dotnet2003 c# i want popup window. calling popup window from parent window is no problem... but i want return value from popup. i have one textbox and one link button in parent window.
1
3237
by: dittu | last post by:
How to close the popup window when submitting the form? I have a sample.jsp. In that page one button is there. when button pressed, open popup window contains one "text box" and one " submit button". when "submit" button pressed, call the "servlet" in this popup window and then close the "popup" window. <SCRIPT LANGUAGE="JavaScript"> <!-- Begin var X = 200; // change the # at the left for a fixed X co-ordinate to accommodate...
8
3402
by: ismailc | last post by:
Good day, I need help. I have an html button that calls & open another browser window on the onMouseUp event, but once I close the popup new browser window my button has focus & is like selected. I want it not to be selected or clicked or has focus, how do i loose the focus after close of popup window? onMouseUp="window.open("
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.