SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detect if window open

    I need a function that when called checks if a window (with a given name) is opened and if so brings it up to front or if it's not opened, opens it to an url...

    help?

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,807
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Just substitute your specific window name for 'specificname' in the following:

    var theWin = window.open('theurl','specificname');
    theWin.focus{}
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    clicking one button opens window with this function:

    function openWin()
    {
    var ver1 = window.open('https://www.google.com','windowOne');
    }

    then, for test purposes another button activates this one:

    function openOrBringToTop()
    {
    if (ver1.closed){
    alert("It's closed!")
    }else{
    alert("It's still open!")
    }
    }

    ...and it doesn't work..?

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,807
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    function openWin()
    {
    var ver1 = window.open('https://www.google.com','windowOne');
    ver1.focus();
    }
    function openOrBringToTop() {openWin();}
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well that brings the window foward yes but also reloads it

  6. #6
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    variable set by one function should be available to other functions, right?
    if pressing one button does this:

    function openOrBringToTop()
    {
    var NewWin = "ThisWindow";
    }

    then pressing another button that links to this function:

    function openWin()
    {
    alert(NewWin);
    }

    should give me a box with "ThisWindow" in it right?

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,807
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    No because you defined NewWin as local to the first function by specifying var. leave off the var and it will then have global scope and work the way you want.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    correct
    thanks


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
  •