Using a toggle/open sindow button

Posted on 2007-08-09
Last Modified: 2013-11-05
I have some code to open a new window that is in page A.

<a href="" class="login" onclick="javascript: secondwindow =open('','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?

Question by:derekstattin
    1 Comment
    LVL 17

    Accepted Solution

    You need to focus on the second window.  Add the following code to the end of your javascript:

    Making the result:
    <a href="#" class="login" onclick="javascript: secondwindow =open('','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.

    - Joe P

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
    The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

    728 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

    18 Experts available now in Live!

    Get 1:1 Help Now