SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Keep javascript working, even if user turned it off

    I know its a noob question. But I heard there is a way for javascript to continue working even if the user turned it off. Perhaps keep the script in a php function and call on it if needed? Can anyone steer me in the right direction, if this is possible?

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    No, this is completely impossible. If Javascript is off, Javascript is off.

    However, a lot of stuff that people use Javascript (incorrectly) for can be done in PHP.

    So, you can determine whether what you are trying to do in Javascript can be done in PHP. If not, it can't be done. However, having Javascript on or off should never break the functionality of a website, if done properly. It just means less dynamic stuff happens without the page reloading.

  3. #3
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,993
    Mentioned
    100 Post(s)
    Tagged
    0 Thread(s)
    Any website should still be usable when the user has javascript turned off.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats the only reason why i dont like using javascript, cause users can turn it off.

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Anything that can be done with JavaScript (except animation) can be done with HTML and a server side scripting language. The only difference is that the server side processing requires the entire page be reloaded for each action while a JavaScript version may not require a reload at all or may just reload part of the page.

    Do any essential processing on the server and use JavaScript to enhance the site for those who have it enabled,
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    To expand on this, let's say you have something like a list of file upload inputs. The number of inputs is based on a number selected from a drop-down. When this drop-down changes, the number of inputs changes (either increasing or decreasing).

    Now, obviously, Javascript can change this number by an action called by a function set in the drop-downs onchange attribute.

    But, you don't want to stop there. What if Javascript is disabled? Do you let it just not work? No, that'd be a bad idea. You can make a couple of changes which will allow it to work using PHP instead of Javascript.

    First, the drop-down would need a button that the user can hit that would update the number of elements. Since you can't use Javascript to add a button (since it's off), you need to have it in the HTML, then remove the unnecessary button with Javascript when it is on.

    That button would then submit the form and tell a PHP script how many files to list. PHP would then give you the number of file inputs required.

    So, basically, the functionality is completely the same. The only difference is that with Javascript it doesn't have to refresh, while without it you do. But, the point is it still works.

    That's graceful degradation.


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
  •