• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 521
  • Last Modified:

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?

 
0
derekstattin
Asked:
derekstattin
1 Solution
 
BogoJokerCommented:
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now