# New Browser Window using AJAX

**URL:** <https://discuss.rubyonrails.org/t/new-browser-window-using-ajax/39981>\
**Category:** rubyonrails-talk\
**Created:** [March 3, 2009, 1:03am UTC](https://discuss.rubyonrails.org/t/new-browser-window-using-ajax/39981 "2009-03-03T01:03:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_L](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@Dave\_L](https://discuss.rubyonrails.org/u/Dave_L)\
**Post date:** [March 3, 2009, 1:03am UTC](https://discuss.rubyonrails.org/t/new-browser-window-using-ajax/39981/1 "2009-03-03T01:03:45Z")

</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:** ![Bill\_Walton1](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Bill\_Walton1](https://discuss.rubyonrails.org/u/Bill_Walton1)\
**Post date:** [March 3, 2009, 1:47am UTC](https://discuss.rubyonrails.org/t/new-browser-window-using-ajax/39981/2 "2009-03-03T01:47:59Z")

</div>

Hi David,

---

<div class="post-metadata">

**Author:** ![Greg\_Donald1](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/greg_donald1/32/1313_2.png) [@Greg\_Donald1](https://discuss.rubyonrails.org/u/Greg_Donald1)\
**Post date:** [March 3, 2009, 5:01am UTC](https://discuss.rubyonrails.org/t/new-browser-window-using-ajax/39981/3 "2009-03-03T05:01:08Z")

</div>

> 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' );"

---

<div class="post-metadata">

**Author:** ![Dave\_L](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@Dave\_L](https://discuss.rubyonrails.org/u/Dave_L)\
**Post date:** [March 3, 2009, 12:08pm UTC](https://discuss.rubyonrails.org/t/new-browser-window-using-ajax/39981/4 "2009-03-03T12:08:40Z")

</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:** ![Greg\_Donald1](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/greg_donald1/32/1313_2.png) [@Greg\_Donald1](https://discuss.rubyonrails.org/u/Greg_Donald1)\
**Post date:** [March 3, 2009, 8:27pm UTC](https://discuss.rubyonrails.org/t/new-browser-window-using-ajax/39981/5 "2009-03-03T20:27:26Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![DPF](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@DPF](https://discuss.rubyonrails.org/u/DPF)\
**Post date:** [March 13, 2009, 3:35pm UTC](https://discuss.rubyonrails.org/t/new-browser-window-using-ajax/39981/6 "2009-03-13T15:35:35Z")

</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:** ![Starr\_Horne](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@Starr\_Horne](https://discuss.rubyonrails.org/u/Starr_Horne)\
**Post date:** [March 13, 2009, 7:26pm UTC](https://discuss.rubyonrails.org/t/new-browser-window-using-ajax/39981/7 "2009-03-13T19:26:07Z")

</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
