# RJS opener.reload()

**URL:** <https://www.ruby-forum.com/t/rjs-opener-reload/143738>\
**Category:** Rails\
**Created:** [July 22, 2008, 11:46am UTC](https://www.ruby-forum.com/t/rjs-opener-reload/143738 "2008-07-22T11:46:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![indra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/5f9b8f/32.png) [@indra](https://www.ruby-forum.com/u/indra)\
**Post date:** [July 22, 2008, 11:46am UTC](https://www.ruby-forum.com/t/rjs-opener-reload/143738/1 "2008-07-22T11:46:38Z")

</div>

Hello,

I have a problem with RJS.

I have a popup and by pressing a button within it I want to:

1. close this popup, which functions fine with onClick in the view and
2. reload the opener page of the popup after the called action in the  
controller is done.

I tried:

render :update do |page|  
page.opener.location.reload()  
end

in the controller, but this didn’t work.

Can anyone please help me?

---

<div class="post-metadata">

**Author:** ![indra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/5f9b8f/32.png) [@indra](https://www.ruby-forum.com/u/indra)\
**Post date:** [July 22, 2008, 12:00pm UTC](https://www.ruby-forum.com/t/rjs-opener-reload/143738/2 "2008-07-22T12:00:08Z")

</div>

On Jul 22, 10:46 am, “Indra M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I tried:
> 
> render :update do |page|  
> page.opener.location.reload()  
> end

You should look at the javascript this generates:  
Opener.location().reload();

try page \<\< “window.opener.location.reload”  
instead

Fred

---

<div class="post-metadata">

**Author:** ![indra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/5f9b8f/32.png) [@indra](https://www.ruby-forum.com/u/indra)\
**Post date:** [July 22, 2008, 12:41pm UTC](https://www.ruby-forum.com/t/rjs-opener-reload/143738/3 "2008-07-22T12:41:18Z")

</div>

On Jul 22, 11:31 am, “Indra M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Doesn’t function, nothing happens.  
> If I don’t close the popup “onClick”
> 
> try {  
> window.opener.location.reload  
> } catch (e) { alert(‘RJS error:\n\n’ + e.toString());  
> alert(‘window.opener.location.reload’); throw e }

Well I left () of the end of that (ie should be reload()).  
How are you calling the controller action. If you’re not making an  
ajax request this will never work (and if you are, don’t use  
the :update option)

Fred

---

<div class="post-metadata">

**Author:** ![indra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/5f9b8f/32.png) [@indra](https://www.ruby-forum.com/u/indra)\
**Post date:** [July 22, 2008, 12:31pm UTC](https://www.ruby-forum.com/t/rjs-opener-reload/143738/4 "2008-07-22T12:31:56Z")

</div>

Thank you for your reply.

Frederick C. wrote:

> You should look at the javascript this generates:  
> Opener.location().reload();
> 
> try page \<\< “window.opener.location.reload”  
> instead

render :update do |page|  
page \<\< “window.opener.location.reload”  
end

Doesn’t function, nothing happens.  
If I don’t close the popup “onClick”

try {  
window.opener.location.reload  
} catch (e) { alert(‘RJS error:\n\n’ + e.toString());  
alert(‘window.opener.location.reload’); throw e }

is displayed in the popup window, instead of executing it.

---

<div class="post-metadata">

**Author:** ![indra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/5f9b8f/32.png) [@indra](https://www.ruby-forum.com/u/indra)\
**Post date:** [July 22, 2008, 1:15pm UTC](https://www.ruby-forum.com/t/rjs-opener-reload/143738/5 "2008-07-22T13:15:45Z")

</div>

Frederick C. wrote:

> Well I left () of the end of that (ie should be reload()).

I appended (), too.

> How are you calling the controller action. If you’re not making an  
> ajax request this will never work (and if you are, don’t use  
> the :update option)

Shame on me. I forgot the ajax request.  
But what do you mean with “don’t use the :update option”?

---

<div class="post-metadata">

**Author:** ![indra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/5f9b8f/32.png) [@indra](https://www.ruby-forum.com/u/indra)\
**Post date:** [July 22, 2008, 1:45pm UTC](https://www.ruby-forum.com/t/rjs-opener-reload/143738/6 "2008-07-22T13:45:55Z")

</div>

On Jul 22, 12:15 pm, “Indra M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Shame on me. I forgot the ajax request.  
> But what do you mean with “don’t use the :update option”?

link\_to\_remote etc… can take an :update option (the id of a dom  
element to update). You shouldn’t use this option at the same time as  
rjs (since this disallows execution of the javascript, it will just be  
dumped into the dom element.

Fred

---

<div class="post-metadata">

**Author:** ![indra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/5f9b8f/32.png) [@indra](https://www.ruby-forum.com/u/indra)\
**Post date:** [July 22, 2008, 2:06pm UTC](https://www.ruby-forum.com/t/rjs-opener-reload/143738/7 "2008-07-22T14:06:52Z")

</div>

Frederick C. wrote:

> On Jul 22, 12:15ï¿½pm, “Indra M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Shame on me. I forgot the ajax request.  
> > But what do you mean with “don’t use the :update option”?
> 
> link\_to\_remote etc… can take an :update option (the id of a dom  
> element to update). You shouldn’t use this option at the same time as  
> rjs (since this disallows execution of the javascript, it will just be  
> dumped into the dom element.

Ah ok. Everything works fine now!

Thank you for your great help, Robert!
