SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    check if window open

    I have a link in a remote window that will blur itself and focus the opener window. The problem that I'm running into now is checking from the opener to see if the remote window is open so I can focus it. Here's what I have so far but I'm getting errors.

    Code:
    if (feedbackWin.closed) {
       feedbackWin=window.open(url,feedbackWin,settings);
    }
    else {
       feedbackWin.focus();
    }
    When running this code from the opener window, it errors out saying feedbackWin is undefined even though the window is actually open.

    I can detect if the opener is still open but its the remote window thats giving me some grief.

    Any suggestions are greatly appreaciated
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1) declare the variable using var first to make sure
    that the fact it's in a logic bundle isn't damping it's
    global use.

    2) do it the other way round: test for the existance of the variable value - and if it exists - focus - if not then open.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    feedbackWin is being defined by the parent via a link to to the following code:

    Code:
    function openFeedbackWindow(thePage) {
      feedbackWin=window.open(thePage,'feedback',settings)
    }
    So do a need to declare another variable in that function to test on or can I test feedbackWin?

    I tried doing something like the following but it opened a new window instead of focusing the existing one.

    Code:
    if (!feedbackWin) {
       feedbackWin=window.open(url,feedbackWin,settings);
    }
    else {
       feedbackWin.focus();
    }
    Thanks for your input!
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  4. #4
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no - declare it outside everywhere to make sure
    it's definately got the right namespace:

    var feedbackWin;

    function ....


    It may not make any difference - but it's good practice
    and may possibly have some bearing.

    The rest seems fine.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  5. #5
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, it's sort of working now... I now have the following code
    Code:
    var feedbackWin;
    if (!feedbackWin) {
       feedbackWin=window.open(url,'feedback',settings);
    }
    else {
       feedbackWin.focus();
    }
    It now focuses the window but reloads its contents instead of leaving what was there originally.

    The child window is a form so a user might fill in some info before clicking the open.parent link... so if possible, I'd like to try to keep their data.

    Thanks again
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  6. #6
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you should put an alert in both the sections of the logic bundle to see what exactly it's doing.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  7. #7
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok... I added 2 alert windows like the following:
    Code:
    var feedbackWin;
    if (!feedbackWin) {
       alert("new window");
       feedbackWin = window.open(url,'feedback', settings);
    }
    else {
       alert("focused");
       feedbackWin.focus();
    }
    When I ran it, the "new window" alert came up. However, that new window is the same as the old one, its just reloaded.
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  8. #8
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    due to the window name.

    Not sure why it's not treating the existance of the variable as a cause to run the else though.

    Someone else might know why though!
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •