# New Browser Window using AJAX

**URL:** <https://www.ruby-forum.com/t/new-browser-window-using-ajax/161846>\
**Category:** Rails\
**Created:** [March 3, 2009, 2:04am UTC](https://www.ruby-forum.com/t/new-browser-window-using-ajax/161846 "2009-03-03T02:04:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 3, 2009, 2:04am UTC](https://www.ruby-forum.com/t/new-browser-window-using-ajax/161846/1 "2009-03-03T02:04:32Z")

</div>

Is it possible to create a new browser window popup with an ajax  
call? I want to open a new window and then trigger window.print()  
like google docs and maps. I know you can create new browser popups  
with link\_to by using :popup =\> [‘new’, ‘height=300,width=300’], but I  
don’t think you can use it with link\_to\_remote. Is there a way to  
programmatically render some inline javascript? I tried:

window.open(‘test/popup’  
‘mywin’,‘left=20,top=20,width=500,height=500,toolbar=1,resizable=0’);

But I was unable to load anything into the popup view.

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 3, 2009, 2:48am UTC](https://www.ruby-forum.com/t/new-browser-window-using-ajax/161846/2 "2009-03-03T02:48:26Z")

</div>

Hi David,

On Mon, 2009-03-02 at 17:03 -0800, David wrote:

> Is it possible to create a new browser window popup with an ajax  
> call? I want to open a new window and then trigger window.print()  
> like google docs and maps.

If I understand what you’re trying to do, you should be able to use  
link\_to\_remote to open a new window and populate it as you please with  
RJS. If you’re new to RJS, grab Cody F.'s .pdf off O’Reilly.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 3, 2009, 6:02am UTC](https://www.ruby-forum.com/t/new-browser-window-using-ajax/161846/3 "2009-03-03T06:02:05Z")

</div>

On Mon, Mar 2, 2009 at 7:03 PM, David [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is it possible to create a new browser window popup with an ajax  
> call?

Yup.

> I want to open a new window and then trigger window.print()  
> like google docs and maps. I know you can create new browser popups  
> with link\_to by using :popup =\> [‘new’, ‘height=300,width=300’], but I  
> don’t think you can use it with link\_to\_remote. Is there a way to  
> programmatically render some inline javascript? I tried:
> 
> window.open(‘test/popup’  
> ‘mywin’,‘left=20,top=20,width=500,height=500,toolbar=1,resizable=0’);
> 
> But I was unable to load anything into the popup view.

html:

\<%= link\_to\_remote ‘Popup’, :url =\> { :controller =\> :home, :action =\>  
:popup } %\>

popup.rjs:

page \<\< “window.open(‘/home/window’, ‘mywin’,  
‘left=20,top=20,width=500,height=500,toolbar=1,resizable=0’ );”

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 3, 2009, 1:09pm UTC](https://www.ruby-forum.com/t/new-browser-window-using-ajax/161846/4 "2009-03-03T13:09:47Z")

</div>

Okay, thanks. Thats what I thought and I have been trying that, but  
I’m wondering, will this trigger the window action of the home  
controller? And do I just add a window view? Is it possible to  
populate that view dynamically within the popup ajax action?

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 13, 2009, 4:36pm UTC](https://www.ruby-forum.com/t/new-browser-window-using-ajax/161846/5 "2009-03-13T16:36:34Z")

</div>

Greg - this “works” but is flagged by popup blockers on IE and  
Firefox. Any thoughts on methods around this?

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 13, 2009, 8:27pm UTC](https://www.ruby-forum.com/t/new-browser-window-using-ajax/161846/6 "2009-03-13T20:27:35Z")

</div>

> Greg - this “works” but is flagged by popup blockers on IE and  
> Firefox. Any thoughts on methods around this?

I don’t know if it helps, but I’ve noticed that browsers will let you  
open a window via JS, as long as the JS was called as a result of a user  
click. The exact same code will be blocked if it’s called by a timer, or  
some other non-user source.

## SH

Starr H.  
My blog: [http://starrhorne.com](http://starrhorne.com)  
Check out my Helpdesk RailsKit: [http://railskits.com/helpdesk/](http://railskits.com/helpdesk/)

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 3, 2009, 9:28pm UTC](https://www.ruby-forum.com/t/new-browser-window-using-ajax/161846/7 "2009-03-03T21:28:10Z")

</div>

On Tue, Mar 3, 2009 at 6:08 AM, Dave L [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Okay, thanks. Thats what I thought and I have been trying that, but  
> I’m wondering, will this trigger the window action of the home  
> controller? And do I just add a window view? Is it possible to  
> populate that view dynamically within the popup ajax action?

It will call whatever you tell it to call in your window.open().

/home/whatever is the same as { :controller =\> :home, :action =\>  
:whatever } .

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)
