Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Javascript new window - activate old if already popped up

Posted on 2008-10-27
7
1,143 Views
Last Modified: 2012-05-05
Hi,

I'm maybe onto nothing here.

I have button that lets user popup a unit calculator, see javascript below. If the user clicks to open it again, instead of opening a another new window, I'd like to activate existing popup...can I do this ?

Thanks in advance
function openConvertor() {
        var load = window.open('../UI/UnitConvertor.aspx','','scrollbars=no,menubar=no,height=450,width=400,resizable=yes,toolbar=no,location=no,status=no');
 
     }

Open in new window

0
Comment
Question by:rwallacej
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 75 total points
ID: 22811891
Just name the window that you are opening in JavaScript.  I believe it is the second parameter you have as blank now.  What this will do is open the JavaScript in the same named window, so as long as it is still open it will use it.
var load = window.open('../UI/UnitConvertor.aspx','MyWIN','scrollbars=no,menubar=no,height=450,width=400,resizable=yes,toolbar=no,location=no,status=no');

Open in new window

0
 
LVL 16

Assisted Solution

by:brad2575
brad2575 earned 125 total points
ID: 22811893
you can just add a check like this:

if (load.closed){
  var  load = window.open('../UI/UnitConvertor.aspx','','scrollbars=no,menubar=no,height=450,width=400,resizable=yes,toolbar=no,location=no,status=no');

}else{
   load.focus();
}
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22811908
Sorry, need more coffee.  Brad2575, nice catch.  I was thinking needed to open in same window, but the question clearly is asking to reactivate existing. :)
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:rwallacej
ID: 22811981
hi, thanks for helpers this is the kind of idea

I have tried code from brad2575 but get "closed" is null or not an object.

There is a page called UnitConvertor.aspx with link, user clicks on that to get popup.
they may navigate away from UnitConvertor.aspx, go to another page, and back and click on the popup again

Thanks for further help
0
 
LVL 10

Accepted Solution

by:
jinn_hnnl earned 300 total points
ID: 22811982
Hi,

The idea is the same but you need a little to make it works.

Put this in your code and test it out

Hope this helps

JINN

var newwindow = '';
 
function openConvertor() {
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = '../UI/UnitConvertor.aspx';
	}
	else {
		newwindow=window.open('../UI/UnitConvertor.aspx', 'myPopup',  'scrollbars=no,menubar=no,height=450,width=400,resizable=yes,toolbar=no,location=no,status=no');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

Open in new window

0
 

Author Closing Comment

by:rwallacej
ID: 31510262
thanks for all the great help :-)

I've split points, hope this is OK with everyone

rwallacej
0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22812065
No problem,

Glad to help ^^

JINN
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question