Forum: Ruby on Rails RJS referring to window.parent

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
F0bf457915a11e25d6744d02362511aa?d=identicon&s=25 Julio Cesar Ody (Guest)
on 2006-05-17 08:52
(Received via mailing list)
Hi all,

I've been doing some work on the Ajax Scaffold
(, to make it work with file uploads
(more specifically, the file_upload plugin).

The first logical step was to get rid of form_remote_tag, since it's
impossible to send files via XMLHTTPRequests (to my best knowledge).
So I referred to the iframe hack, similar to the upload progress bar
here (

The way I found to perform an action upon successful form submission
was to include javascript code in the response view, which will be
rendered in the hidden iframe. It gets executed, it works perfectly

But here's the problem: I wanted to simply "import" the RJS files that
come with the Ajax Scaffold. The way I figured to do that was to do
write my view (the one getting rendered in the hidden iframe) like

#### BEGIN CODE ####
 <%= javascript_include_tag :defaults %>
 <script type="text/javascript">
  <%= render :update do |page|

         # all the RJS goes here

         end %>
#### END CODE ####

Sounds like it will work. But here's the catch: all the elements that
the RJS code above is referring to are supposed to be in the same page
where the output javascript is. The only way to refer to them is to
preceed their ID's with "window.parent.document.getElementById", so
the code inside the iframe is actually targetting the page "hosting"
it, and that's where the elements we want to manipulate are.

So my question is: is there a way to do it via RJS? I thought that
something like "page.parent" existed, but it doesn't. It also comes to
my mind a hack, where the parameters you supply to the RJS functions
don't get quoted, meaning if I did something like this:

page.visual_effect :highlight,

It would output "window.parent..." with no surrounding quotes. If that
worked, Prototype would find the element just fine.

The only other choice I have here is actually fetching all the JS
output, and writing it all in the view, changing the target for the
Prototype functions. But that sounds cranky to me.

Any ideas?
This topic is locked and can not be replied to.