Solved

Javascript new window - activate old if already popped up

Posted on 2008-10-27
7
1,141 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

770 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