#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2001
    Location
    In a multi-cultural mess.
    Posts
    569
    Rep Power
    14

    How can I tell whether a browser has javascript enabled?


    I had posted this to the HTML / JAVASCRIPT forum some weeks ago,
    but now decided to try here.

    How can I tell whether a browser has javascript enabled?

    I want to pop a "help" window in a "new" location so the user
    is aware that there are now 2 windows -- the help window
    and the "main" window that the help refers to.

    To do this, it seems that I must use javascript window.open( ...
    How can I tell whether a browser has javascript enabled?

    Robert
    Robert
    ---
    If it's hard, it's probably wrong.
  2. #2
  3. Newbie :P
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Jan 2001
    Location
    In the PHP Engine :-)
    Posts
    2,880
    Rep Power
    21

    Lightbulb Because it won't work ;-)


    Sorry couldn't resist, I'm not sure that there is any way to detect it because a users browser settings I would think are a private thing and were not designed for us to explore.

    I could be wrong though.
    ---------------------
    -- SilkySmooth --
    ---------------------
    Proxy
  4. #3
  5. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    First off, you do realize that there is an html href tag property called 'target' that allows you to open links in a new window, right? You have no say over the size of the window, but if it absolutely must be in a new window even if JS is off, use 'target=_blank'.

    Having said that, Here is how I make my links using the open function so that I know it will still work with non-JS enabled browsers

    Code:
    <a href="http://www.clanmisfire.com" target="_blank" 
      onClick='window.open("http://www.clanmisfire.com",
                  "",
                  "height=750,width=590,resizable=yes,scrollbars=yes");    return false;'>
    Now, let me explain what that is doing.

    If a browser has JS ENABLED, it first executes the onClick event handler. The function window.open runs, opening a new window. Then the next line, return false;, executes. This keeps the browser from going any farther for this href tag. In other words, it does NOT act like a link and follow the href property.

    If a browser has JS DISABLED, it ignores the onClick property and goes straight for the href. It opens the link in a new window anyway. The only thing is that you have no say over what that new window looks like. I think for the small percentage of ppl that have JS turned off, this is acceptable considering they can still get to the content.

IMN logo majestic logo threadwatch logo seochat tools logo