Get width of an element using javascript

I need to get the width of an element into a ruby variable.

I have tried using various methods to call a javascript function that’s
in the prototype library called getDemensions. I’m just not sure how to
perform the call.

document.GetElementById(id).offsetWidth works fine with and onClick
event, but I need to get the width value at various time during the page
load. I also tried the remote_function and javascript_tag methods, to no
avail.

How do I call javascript without an event in rails?

Any suggessions?