Determing JS+AJAX vs. button

I'd like to use on browsers supporting AJAX link_to_remote or button_to_function/remote_function and on rest button_to and link_to.

How can I determine it?

Maciej Piechotka wrote:

I'd like to use on browsers supporting AJAX link_to_remote or button_to_function/remote_function and on rest button_to and link_to.

How can I determine it?

Send both systems, and let the browser figure it out, like this:

  <noscript>     <%= my manual buttons %>   </noscript>

  <%= javascript_tag ... %>

A browser without JavaScript will render the HTML inside <noscript>, so put your buttons there. And only a browser _with_ JavaScript will respect the <script> tags that javascript_tag inserts, so I suspect you could put 'document.write' calls in there that insert your link_to_remote tags.

/Pragmatic Ajax/ has a great section on degradability, but I don't know if it has the <noscript> trick.

Thank you - sometimes I forget about those base (x)html tricks...

Regards

Maciej,

  > I'd like to use on browsers supporting AJAX link_to_remote or   > button_to_function/remote_function and on rest button_to and link_to.

link_to_remote offers fallback for js-challenged browsers, so this code would do what you need :(untested)

  <%= link_to_remote "Delete",     {:url => {:action => "delete", :id => id} }, ## <-- if JS available     {:href => url_for(:action => "delete",:id => id)} ## <- if NO JS   %>

, and in the controller you'd use 'respond_to' to handle both calls within one action.

Alain Ravet

Thanks. That is just what I wanted.

Regards