Using a toggle/open sindow button

I have some code to open a new window that is in page A.

<a href="" class="login" onclick="javascript: secondwindow =open('http://www.site.com/login.php','login','height=900, width=900, scrollbars=yes,resizable=yes,top=100,left=100,screenx=100,screeny=100,addressbar=1,toolbar=1,statusbar=1,menubar=1')">-login-</a>

1.When the user opens the new window, Page B, using the link above,
2. Then goes back to page A,
3. Then clicks the link in page A(ie the link above again), I would like the link to "toggle", rather than try to open a window that is already open.

Just using the code above, the second window stays behind the first.

Do I just need to use a toggle, or a combination of open window and toggle, where javascript recognizes if the window B is already open? Can you help me modify the code above?

 
derekstattinAsked:
Who is Participating?
 
BogoJokerConnect With a Mentor Commented:
You need to focus on the second window.  Add the following code to the end of your javascript:
secondwindow.focus();

Making the result:
<a href="#" class="login" onclick="javascript: secondwindow =open('http://www.site.com/login.php','login','height=900, width=900, scrollbars=yes,resizable=yes,top=100,left=100,screenx=100,screeny=100,addressbar=1,toolbar=1,statusbar=1,menubar=1'); secondwindow.focus();">-login-</a>

Also notice that I made the href="#" which is an anchor to the current page.

Enjoy,
- Joe P
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.