Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hide or close the browser tab when its inactive using native javascript?

    How to hide or close the browser tab when this tab is inactive, or the user switch into another tab using pure JavaScript?

    Example: When the tab is open the Google Map, and the user switch into another tab, the Google Map tab will be hide or close. Thank you

    I'm new in javascript. Please help me

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,783
    Thanks
    6
    Thanked 1,022 Times in 995 Posts
    I suppose you can combine onblur and close. I don’t get the point of this, though. From a user experience and interaction point of view that makes no sense.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    Also, in general you aren't allowed to affect windows (including tabs) that you didn't open.

    You said "native javascript" so there are probably ways to do this in *SOME* browsers, but it almost surely will not be cross-browser compatible.

    If somebody knows I'm wrong, would love to hear about it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,401
    Thanks
    11
    Thanked 595 Times in 575 Posts
    you can do this in firefox by changing the about:config pref "dom.allow_scripts_to_close_windows", and then calling window.close() on the tab you want to close.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    Sorry: I meant if anyone knew of a way to do it universally, across all browsers.

    I did say
    there are probably ways to do this in *SOME* browsers, but it almost surely will not be cross-browser compatible.
    This can also be done with IE in some circumstances, but in no way resembling what FF uses.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

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