Results 1 to 6 of 6
  1. #1
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaScript close window (Firefox)

    I use a simple JavaScript call to close the current window on a web page and it works fine in IE (after prompting the user if it's ok) but does nothing in Firefox.
    <pre>Close this Window</pre>

    I set my FF to have multiple tabs and had different pages on each tab. I expected this page's tab to close but nothing happened.

    What is the right way to do this in FF? <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

    Thnx, Deb

  2. #2
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: JavaScript close window (Firefox)

    I should of done more searching on my own before posting this but I still don't have a fix. I searched around and see this is a known FF problem and a few JavaScript solutions were offered but so far none are working.
    <pre>function winClose()
    {
    if(navigator.appName=="Microsoft Internet Explorer") {
    this.focus();self.opener = this;self.close(); }
    else { window.open('','_parent',''); window.close(); }
    }</pre>

    I called this function in my href tag and it worked in IE but not FF. I got this from http://www.guyfromchennai.com/?p=18 which says it works but other searches said FF 2.0 "fixed" this such that the workaround doesn't work.

    I'll keep looking and if I find one which works on FF I'll post it here but if anyone else comes across a working solution let me know. <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>

  3. #3
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: JavaScript close window (Firefox)

    Ok I think I figured this out but it still doesn't work. In FF I opened the Error Console and clicked the 'close this window' link and the displayed error message said "Scripts may not close windows that were not opened by script." These windows were however opened with a call to javascript in the HREF tag so I don't know what to change.
    <pre>Close this Window</pre>

    The window is opened like this with showMap() loading map.shtml page to a given size. If this isn't opening a page with a script I don't know what the FF error message means. Oh well, I guess I won't spend anymore time on this. Just another irritant to multi-browser support and testing.

    I also tried just onClick but that didn't work either <pre><a onClick="java script:window.open('java script:window.close();','_self','');">Close this Window</a></pre>


    Deb

  4. #4
    5 Star Lounger
    Join Date
    Dec 2002
    Location
    Perth, Western Australia, Australia
    Posts
    730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: JavaScript close window (Firefox)

    (A shot in the dark) re "Scripts may not close windows that were not opened by script.".

    Could that translate to "only the script that opened a window may close it" ?

    If that is nonsensical, please ignore. (I don't develop scripts, just hack others efforts to effect minor fixes or tweaks.)
    <font face="Comic Sans MS" color="blue">TimOz</font>
    <img src=/S/flags/Finland.gif border=0 alt=Finland width=30 height=18> <img src=/S/flags/Australia.gif border=0 alt=Australia width=30 height=18>

  5. #5
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: JavaScript close window (Firefox)

    Yes I considered that too but if that's the case, I don't understand how it'd work. If I have Javascript in fileA.html which opens fileB.html when some action (button click, mouseover, etc.) occurs, then that to me is a window which was launched by a script. If they mean I can only open another copy of fileA.html then that's not at all useful. Maybe I can find a list of error messages for FF more and get an explanation of what that one really means.

    Thanks for the thought though. Writing code that works cross-browser has always been a major problem (altho it's not as bad now as it was in the past).

    Deb

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: JavaScript close window (Firefox)

    This is a frequent topic on the mozillaZine Web Development board. Basically, the developers keep closing all the known loopholes that in the past allowed JavaScript to close the current window if the window was not opened using the window.open() method.

Posting Permissions

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