# Executing a static javascript function after every event

**URL:** <https://www.ruby-forum.com/t/executing-a-static-javascript-function-after-every-event/110228>\
**Category:** Rails\
**Created:** [July 24, 2007, 2:30pm UTC](https://www.ruby-forum.com/t/executing-a-static-javascript-function-after-every-event/110228 "2007-07-24T14:30:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![prism](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@prism](https://www.ruby-forum.com/u/prism)\
**Post date:** [July 24, 2007, 2:30pm UTC](https://www.ruby-forum.com/t/executing-a-static-javascript-function-after-every-event/110228/1 "2007-07-24T14:30:36Z")

</div>

Hi,

is there any way to (automatically?) call a javascript function  
whenever something has happened in the view? Or at least when the view  
has changed.

I.e. I have a function that vertically resizes and positions elements  
on a page after checking the content, and I’d like it to update those  
every time the content has changed.

With , it only works for the first view, “/” or  
“/frontpage/”, but not the rest.

The html, head (and script), body tag, etc is located in a partial,  
\_a.rhtml, that is in views/layouts and is used across the different  
views, like frontpage.rhtml, news.rhtml and so on.

Thanks,  
Bjørn

---

<div class="post-metadata">

**Author:** ![prism](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@prism](https://www.ruby-forum.com/u/prism)\
**Post date:** [July 24, 2007, 4:10pm UTC](https://www.ruby-forum.com/t/executing-a-static-javascript-function-after-every-event/110228/2 "2007-07-24T16:10:41Z")

</div>

prism wrote:

> is there any way to (automatically?) call a javascript function  
> whenever something has happened in the view? Or at least when the view  
> has changed.

My Short Cut with O’Reilly describes how to abuse^W activate the  
prototype.js handlers like this:

Ajax.Responders.register({ onComplete: function(request) {…} } )

Then detect your event type inside that handling method.

–  
Phlip  
[http://www.oreilly.com/catalog/9780596510657/](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax
