SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello all

    trying to do something simply but keep failing to get it right, spawning a window with :

    function NewWindow1() {
    act = window.open("act_pre.htm", "act");
    }

    this works fine, then trying to close it from the original window with :

    function closewindow()
    act.close();
    }

    this does'nt work, i know the script is being called cos if i just put close() the origin window closes fine. Can anyone see where i am going wrong, naming the spawned window or calling its name when trying to close it.

    any help appreciated, thanks!
    gar

  2. #2
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If my memory serves me right, I believe it's only 'window.close()', not 'act.close'. Try:
    Code:
    window.close('act')
    Although I'm not sure if it will work well. 'window.close()' usually does the trick for me.

    Hope this helped.
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  3. #3
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also, if the code you're running to close the window is INSIDE the window itself, you can use:
    Code:
    self.close()
    That works very nicely. It doesn't even pop up those annoying messages in I.E saying "are you SURE you want to close the window?". All in all, it's a good function.
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  4. #4
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    >also, if the code you're running to close the window is >INSIDE the window itself, you can use:
    >self.close()

    its not so i can't

    >window.close('act')

    nope first thing i thought of! if only it was that easy!

    window.close()
    close()

    result in the same thing in fact. thanks for the help anyway!

    Garrett

  5. #5
    SitePoint Member
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Garrett,
    If you have spawned a new popup window from your main page using javascript and want to close it from your main page, you can do this using a simple text link.

    <a href="javascript: act.close();">CLOSE WIN</a>

    Good luck

  6. #6
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    as i already said above the closing button is not in the same winow as the opening button this is why the problem arises.

    thanks for you help
    garrett

  7. #7
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Garett,

    As you've written your code, act is a local variable. That is, it's created by NewWindow1() and then is destroyed as soon as the function ends. What you need to do is declare the variable global:

    Code:
    var act = null;
    
    function NewWindow1() { 
      act = window.open("act_pre.htm", "act"); 
    } 
    
    function closewindow() {
      if (act) act.close();
    }
    That should work. Let me know if you still have trouble!
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  8. #8
    SitePoint Addict gthorley's Avatar
    Join Date
    Oct 2000
    Location
    Canada
    Posts
    392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have popups to show enlarged pictures on my wifes art site. I load the following into each new popup
    <body bgcolor="#000000" onBlur="window.close()">. In addition I plan to also put a link on the cosmetic only "close window" text to close( all thats needed is <a href="Javascript:window.close ()">) as I have discovered the onblur function doesn't seem to work in NS6 and Opera.

    This then closes the window whenever a mouseclick occurs on either the popup or the original page.

    No guarantees as I have'nt a clue about programming. This info was gleaned from help from others but it seems to work for me.


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
  •