• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Is javascript enabled?

 
Ranch Hand
Posts: 837
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I check to see if javascript is enabled from code? I have a perl/cgi application that generates HTML pages which has javascript validation scripts on them. I want a way to check whether javascript is enabled or what the user's browser settings are in relation to security. I need to know this so as to warn the user before getting too deep into the web application and before hitting javascript dependent pages. Is there a way of accomplishing this (i.e. environment variables passed back, etc..,)? Thanks.

Rob
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All you can do is have JavaScript set a form value on the page when it loads. When a post back happens and you do not see the value, than you know they do not have it enabled.

Eric
 
Rob Hunter
Ranch Hand
Posts: 837
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Eric. I was hoping there might be something client-side I could do, guess I'll need a workaround then.

Rob
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<html>
<head>
<title></title>
</head>
<body>

<script language="javascript">
<!--
document.write("You have javascript enabled");
-->
</script>
<noscript>
You do not have javascript enabled.
</noscript>
</body>
</html>

If you want to let the server know if js is enabled, set a cookie using js and check for it on the server. Or, if it is a form submittal put a hidden field in <noscript> and check it on the server.
 
Rob Hunter
Ranch Hand
Posts: 837
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <noscript> would be my best bet since I want this check done immediately on a page (multiple navigation routes to the page) and before the form gets a chance to be submitted. Thanks for the response, I'll give it a try.

Rob
 
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic