?
Solved

Javascript new window - activate old if already popped up

Posted on 2008-10-27
7
Medium Priority
?
1,150 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
[X]
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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 60

Assisted Solution

by:Kevin Cross
Kevin Cross earned 300 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 500 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 60

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…
Suggested Courses

764 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