Solved

Javascript new window - activate old if already popped up

Posted on 2008-10-27
7
1,140 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now