szimek
2008-Jun-24 09:34 UTC
How to send window.location.hash (string after # in the url) along post request
Hi, I got some old javascript tab system and I''m trying to rewrite it to make use of window.location.hash to set proper tab after the page is loaded. It more or less works, but the main problem is that I got some forms and I don''t know how to set their url correctly, so that after the form is sent, proper tab is opened again. I.e. page under "domain.com/foo/1#tab_1" has a form that points to "domain.com/foo/1/update". Is it possible to somehow send window.location.hash along the whole request, so that after handling the request I can redirect user back to "domain.com/foo/1#tab_1"? I could use remote forms, so that user always stays on the same page, but I''d prefer not to use them, unless it can''t be done in any other way. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Phillip Koebbe
2008-Jun-24 10:50 UTC
Re: How to send window.location.hash (string after # in the
Szymon Nowak wrote:> Hi, > > I got some old javascript tab system and I''m trying to rewrite it to > make use of window.location.hash to set proper tab after the page is > loaded. It more or less works, but the main problem is that I got some > forms and I don''t know how to set their url correctly, so that after > the form is sent, proper tab is opened again. > > I.e. page under "domain.com/foo/1#tab_1" has a form that points to > "domain.com/foo/1/update". Is it possible to somehow send > window.location.hash along the whole request, so that after handling > the request I can redirect user back to "domain.com/foo/1#tab_1"? > > I could use remote forms, so that user always stays on the same page, > but I''d prefer not to use them, unless it can''t be done in any other > way.You should be able to use some javascript to set a hidden form field. Maybe onsubmit of the form or onclick of the submit button. The first thing I''d try is form_tag(blah) hidden_field_tag :location_hash blah blah submit_tag ''Save'', :onclick => "$(''location_hash'').value = window.location.hash" end Keep in mind that I haven''t been up very long. Peace, Phillip -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---