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
    9,152
    Thanks
    6
    Thanked 1,076 Times in 1,048 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
    29,353
    Thanks
    83
    Thanked 4,904 Times in 4,865 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.
    Be yourself. No one else is as qualified.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,564
    Thanks
    11
    Thanked 612 Times in 592 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 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    29,353
    Thanks
    83
    Thanked 4,904 Times in 4,865 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.
    Be yourself. No one else is as qualified.


  •  

    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
    •