How to: Check if Javascript is enabled

130 views
Skip to first unread message

Tom Ha

unread,
Nov 11, 2009, 8:27:53 AM11/11/09
to rubyonra...@googlegroups.com
Hi there,

Rails has fantastic Javascript helpers, which I have immediately used
for my website.

Since some features of my website now rely 100% on Javascript being
enabled in the user's browser, I now need a way to either:
a) block the usage of the site when Javascript is disabled, or
b) display a very visible message that tells the user to enable
Javascript.

Has anybody good ideas for a plugin (or some other solution) to check if
Javascript is enabled and to then let the user know?

(I know, a good programmer would let the site work without JS as well,
but currently, I'm not there yet...)

Thanks a bunch for any help with this!
Tom
--
Posted via http://www.ruby-forum.com/.

Jeffrey L. Taylor

unread,
Nov 11, 2009, 8:56:50 AM11/11/09
to rubyonra...@googlegroups.com
Quoting Tom Ha <rails-mai...@andreas-s.net>:
>
> Hi there,
>
> Rails has fantastic Javascript helpers, which I have immediately used
> for my website.
>
> Since some features of my website now rely 100% on Javascript being
> enabled in the user's browser, I now need a way to either:
> a) block the usage of the site when Javascript is disabled, or
> b) display a very visible message that tells the user to enable
> Javascript.
>
> Has anybody good ideas for a plugin (or some other solution) to check if
> Javascript is enabled and to then let the user know?
>

There is a <noscript> tag in HTML that does what you want.

http://www.w3schools.com/TAGS/tag_noscript.asp

HTH,
Jeffrey

Marnen Laibow-Koser

unread,
Nov 11, 2009, 9:21:37 AM11/11/09
to rubyonra...@googlegroups.com
Tom Ha wrote:
> Hi there,
>
> Rails has fantastic Javascript helpers, which I have immediately used
> for my website.

Actually, Rails has terrible JS helpers: they encourage a poor style of
programming where JS is mixed into HTML. Generally, this is not a good
idea.

>
> Since some features of my website now rely 100% on Javascript being
> enabled in the user's browser, I now need a way to either:
> a) block the usage of the site when Javascript is disabled, or
> b) display a very visible message that tells the user to enable
> Javascript.

The <noscript> tag will work, or you could have a message in the HTML
that your JS code will remove.

>
> Has anybody good ideas for a plugin (or some other solution) to check if
> Javascript is enabled and to then let the user know?
>
> (I know, a good programmer would let the site work without JS as well,
> but currently, I'm not there yet...)

Get there! Read about progressive enhancement.

>
> Thanks a bunch for any help with this!
> Tom

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org

Leonardo Mateo

unread,
Nov 11, 2009, 9:46:38 AM11/11/09
to rubyonra...@googlegroups.com
On Wed, Nov 11, 2009 at 3:21 PM, Marnen Laibow-Koser
<rails-mai...@andreas-s.net> wrote:
>
> Tom Ha wrote:
>> Hi there,
>>
>> Rails has fantastic Javascript helpers, which I have immediately used
>> for my website.
>
> Actually, Rails has terrible JS helpers: they encourage a poor style of
> programming where JS is mixed into HTML.  Generally, this is not a good
> idea.
>
>>
>> Since some features of my website now rely 100% on Javascript being
>> enabled in the user's browser, I now need a way to either:
>> a) block the usage of the site when Javascript is disabled, or
>> b) display a very visible message that tells the user to enable
>> Javascript.
>
> The <noscript> tag will work, or you could have a message in the HTML
> that your JS code will remove.
>
>>
>> Has anybody good ideas for a plugin (or some other solution) to check if
>> Javascript is enabled and to then let the user know?
>>
>> (I know, a good programmer would let the site work without JS as well,
>> but currently, I'm not there yet...)
>
> Get there!  Read about progressive enhancement.
+1
Not only for this, (because I think that using JavaScript in, almost,
the year 2010 is more than OK), but just because you have to.

--
Leonardo Mateo.
There's no place like ~

Tom Ha

unread,
Nov 11, 2009, 11:05:53 AM11/11/09
to rubyonra...@googlegroups.com
:-) Thanks, guys!
Reply all
Reply to author
Forward
0 new messages