# How to execute javascript after redirect?

**URL:** <https://www.ruby-forum.com/t/how-to-execute-javascript-after-redirect/133172>\
**Category:** Rails\
**Created:** [March 28, 2008, 3:12pm UTC](https://www.ruby-forum.com/t/how-to-execute-javascript-after-redirect/133172 "2008-03-28T15:12:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [March 28, 2008, 3:12pm UTC](https://www.ruby-forum.com/t/how-to-execute-javascript-after-redirect/133172/1 "2008-03-28T15:12:46Z")

</div>

Hi,

I’ve got a form with create and preview buttons - both point to create  
action, but if create button was pressed, user is redirected to show  
action, if preview was pressed user is redirected to edit action.

After redirecting to edit action I’d like to execute some javascript  
code, but only if user gets there using preview button. Is there some  
smart way to do it or should I simply pass additional parameter (item/  
1/edit?preview=true or something like this) and check for it in the  
view?

Thanks

---

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [March 31, 2008, 8:37am UTC](https://www.ruby-forum.com/t/how-to-execute-javascript-after-redirect/133172/2 "2008-03-31T08:37:11Z")

</div>

I believe you can see which button was pressed in the params. (It might  
be the ‘commit’ param). You might have to give the buttons the ‘name’  
attribute for this to work.

Hope this is mildy helpful
