Is there a simple way to tell if the browser you are talking to supports javascript and has it turned on? I''d like to set a variable to that effect. Thanks. --David. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
David, Ummm....if it doesn''t support JavaScript, what kind of "variable" are you talking about? Server-side? ''Cause if there is no client-side JavaScript, there are no client-side JavaScript variables. Or perhaps you mean a cookie? You can definitely test whether JavaScript is enabled: Have the page assume that it isn''t, and then use JavaScript to change that assumption if it is. The two main variations on this theme, off the top of my head, are: 1. Have a page that''s fully-functional without JavaScript, but gets "spruced up" by JavaScript if it''s enabled. No "detection" per se is required, it''s just that the sprucing up won''t happen if the client doesn''t have JavaScript. 2. Have a small intro page that redirects to a version of your page that doesn''t use JavaScript if JavaScript isn''t enabled, or to a version that does if it is. You can easily do that by having JavaScript trigger a page load (by setting location.href) immediately, and having a meta refresh fallback that happens after a pause (e.g., if the JavaScript thing hasn''t happened). In either case, if you like you can set a cookie to remember whether JavaScript is loaded for subsequent page loads (have the page set the cookie to "not enabled", and set it to "enabled" via JavaScript in the page), although if the browser supports JavaScript the user can change whether it''s enabled between page loads, so your cookie can get out of date. Users don''t typically do that, of course. Hope this helps, -- T.J. Crowder tj / crowder software / com On Jun 29, 4:45 am, djlewis <djlew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is there a simple way to tell if the browser you are talking to > supports javascript and has it turned on? I''d like to set a variable > to that effect. > > Thanks. --David.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 29, 9:40 pm, "T.J. Crowder" <t...-MUGVhKWuB3Yd9SLi6J12IkEOCMrvLtNR@public.gmane.org> wrote:> David, > > Ummm....if it doesn''t support JavaScript, what kind of "variable" are > you talking about? Server-side? ''Cause if there is no client-side > JavaScript, there are no client-side JavaScript variables. Or perhaps > you mean a cookie?Given the rise in use of extensions like NoScript, it is likely that even if some of the scripts in the page work, others won''t if they load from a different URI. For example, I frequently allow scripts from the site I''m visiting but don''t allow Urchin tracker or google analytics.> You can definitely test whether JavaScript is enabled: Have the page > assume that it isn''t, and then use JavaScript to change that > assumption if it is. The two main variations on this theme, off the > top of my head, are:That will probably work a good percentage of the time but it isn''t foolproof. It may also be that the detection method itself failed.> 1. Have a page that''s fully-functional without JavaScript, but gets > "spruced up" by JavaScript if it''s enabled. No "detection" per se is > required, it''s just that the sprucing up won''t happen if the client > doesn''t have JavaScript.Or if the javascript fails to execute properly.> 2. Have a small intro page that redirects to a version of your page > that doesn''t use JavaScript if JavaScript isn''t enabled, or to a > version that does if it is. You can easily do that by having > JavaScript trigger a page load (by setting location.href) immediately, > and having a meta refresh fallback that happens after a pause (e.g., > if the JavaScript thing hasn''t happened).Unless the meta refresh has been disabled too.> In either case, if you like you can set a cookie to remember whether > JavaScript is loaded for subsequent page loads (have the page set the > cookie to "not enabled", and set it to "enabled" via JavaScript in the > page), although if the browser supports JavaScript the user can change > whether it''s enabled between page loads, so your cookie can get out of > date. Users don''t typically do that, of course.They do, using extensions like NoScript, and they may also disable cookies too. The usual strategy for web sites is to make them functional without scripting, then tart them up with script. Some sites also give visitors subtle hints that scripting would allow them better functionality. -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the replies. So, I take it there is no ~simple~ way to detect javascript-ness, like looking at user_agent. Anything involves some trick or another, and requires some interaction with attempted js that "fails". I was kinda hoping that Prototype or Script.aculo.us had a function built-in that gave you the answer. I just want to set a session variable so I know not even to bother with js interactions. I realize the holy grail is gracefully degrading (or incrementally enhanced) interaction, but my reading (and experimenting) so far indicates that is not always easy. Besides, I''m just getting started with js on rails, and wanted to experiment a bit. --David. On Jun 29, 7:40 am, "T.J. Crowder" <t...-MUGVhKWuB3Yd9SLi6J12IkEOCMrvLtNR@public.gmane.org> wrote:> David, > > Ummm....if it doesn''t support JavaScript, what kind of "variable" are > you talking about? Server-side? ''Cause if there is no client-side > JavaScript, there are no client-side JavaScript variables. Or perhaps > you mean a cookie? > > You can definitely test whether JavaScript is enabled: Have the page > assume that it isn''t, and then use JavaScript to change that > assumption if it is. The two main variations on this theme, off the > top of my head, are: > > 1. Have a page that''s fully-functional without JavaScript, but gets > "spruced up" by JavaScript if it''s enabled. No "detection" per se is > required, it''s just that the sprucing up won''t happen if the client > doesn''t have JavaScript. > > 2. Have a small intro page that redirects to a version of your page > that doesn''t use JavaScript if JavaScript isn''t enabled, or to a > version that does if it is. You can easily do that by having > JavaScript trigger a page load (by setting location.href) immediately, > and having a meta refresh fallback that happens after a pause (e.g., > if the JavaScript thing hasn''t happened). > > In either case, if you like you can set a cookie to remember whether > JavaScript is loaded for subsequent page loads (have the page set the > cookie to "not enabled", and set it to "enabled" via JavaScript in the > page), although if the browser supports JavaScript the user can change > whether it''s enabled between page loads, so your cookie can get out of > date. Users don''t typically do that, of course. > > Hope this helps, > -- > T.J. Crowder > tj / crowder software / com > > On Jun 29, 4:45 am,djlewis<djlew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Is there a simple way to tell if the browser you are talking to > > supports javascript and has it turned on? I''d like to set a variable > > to that effect. > > > Thanks. --David.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
How could Prototype or Scriptaculous tell you whether JavaScript is enabled?! They''re JavaScript libraries! Am I misunderstanding something? -Fred On Tue, Jul 1, 2008 at 9:16 AM, djlewis <djlewis9-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I was kinda hoping that Prototype or Script.aculo.us had a function > built-in that gave you the answer. I just want to set a session > variable so I know not even to bother with js interactions.-- Science answers questions; philosophy questions answers. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---