Solved

Javascript new window - activate old if already popped up

Posted on 2008-10-27
7
1,138 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

706 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