# Trouble with popup window

**URL:** <https://www.ruby-forum.com/t/trouble-with-popup-window/80615>\
**Category:** Rails\
**Created:** [December 29, 2006, 9:17am UTC](https://www.ruby-forum.com/t/trouble-with-popup-window/80615 "2006-12-29T09:17:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shauna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@shauna](https://www.ruby-forum.com/u/shauna)\
**Post date:** [December 29, 2006, 9:17am UTC](https://www.ruby-forum.com/t/trouble-with-popup-window/80615/1 "2006-12-29T09:17:10Z")

</div>

I would like to have a “Print” link which when clicked, calls my  
print\_list method to populate the print\_list view, then opens the  
print\_list view in a NEW browser window. I’m using Firefox 1.5.0.9.

So far I have:  
\<%= link\_to “Print”, :action =\> ‘print\_list’, :popup =\> true %\>

This partially works - it calls the print\_list method which properly  
generates and populates the view. However, I can’t get it to come up in  
a NEW window instead of overlaying my current window. I’ve tried  
various permutations of braces and using variables instead of “true”.  
Here’s another example of what I’ve been trying:

```
<%= link_to "Print", {:action => 'print_list'}, {:popup =>

```

[‘new\_window’, ‘height=300,width=600’]} %\>

But how can I get a NEW window to pop up with my printable view in it?

Also, I’d like to have the File|Print dialog box automatically come up  
when the new window opens. How do I get that to happen?

Thanks for the help,  
Shauna

---

<div class="post-metadata">

**Author:** ![shauna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@shauna](https://www.ruby-forum.com/u/shauna)\
**Post date:** [December 29, 2006, 5:48pm UTC](https://www.ruby-forum.com/t/trouble-with-popup-window/80615/2 "2006-12-29T17:48:50Z")

</div>

On Fri, 2006-12-29 at 00:16 -0800, shauna wrote:

> various permutations of braces and using variables instead of “true”.  
> Here’s another example of what I’ve been trying:
> 
> \<%= link\_to “Print”, {:action =\> ‘print\_list’}, {:popup =\>  
> [‘new\_window’, ‘height=300,width=600’]} %\>
> 
> But how can I get a NEW window to pop up with my printable view in it?
> 
> Also, I’d like to have the File|Print dialog box automatically come up  
> when the new window opens. How do I get that to happen?

* * *

try  
\<%= link\_to “Print”, , {:action =\> ‘print\_list’, :id =\>  
whatever.id}, :popup =\> [‘new\_window’, ‘height=300,width=600’] %\>

Craig

---

<div class="post-metadata">

**Author:** ![shauna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@shauna](https://www.ruby-forum.com/u/shauna)\
**Post date:** [December 29, 2006, 11:29pm UTC](https://www.ruby-forum.com/t/trouble-with-popup-window/80615/3 "2006-12-29T23:29:56Z")

</div>

Hi Craig,

I tried your permutation and the results are no different. It displays  
the print\_list view in the same browser tab, overwriting the original  
page. I want the original page to remain and the printable page to come  
up in a new browser window.

By the way, my action doesn’t usea specific id - it’s just a list of the  
entire table in the order the user has picked.

Shauna

---

<div class="post-metadata">

**Author:** ![shauna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@shauna](https://www.ruby-forum.com/u/shauna)\
**Post date:** [December 30, 2006, 12:04am UTC](https://www.ruby-forum.com/t/trouble-with-popup-window/80615/4 "2006-12-30T00:04:17Z")

</div>

This is an example from my current project that I know opens a new  
window:

\<%= link\_to ‘Preview’,{ :controller =\> ‘publish’, :action =\> ‘preview’,  
:id =\> page }, :popup =\> true %\>

If you don’t have an id then just leave it out.

If it is still displaying in the same browser tab then it is probably  
your browser setting.

hope that helps -K

---

<div class="post-metadata">

**Author:** ![shauna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@shauna](https://www.ruby-forum.com/u/shauna)\
**Post date:** [December 30, 2006, 2:37am UTC](https://www.ruby-forum.com/t/trouble-with-popup-window/80615/5 "2006-12-30T02:37:58Z")

</div>

Thanks, Kim. I tried fiddling with the Firefox settings and that made no  
difference.

Other sites can open new windows from my browser so I know it can be  
done, but they use non-Rails methodology for that aspect. For example,  
the ZiYa plugin at [http://liquidrail.com/](http://liquidrail.com/) (recently announced on this  
list) opens a new window when I click on a chart image. Also, Google  
Docs and Spreadsheets at [http://docs.google.com/](http://docs.google.com/) opens a new window to  
print a document.

But I want to know how to do it within my Erb command so I don’t have to  
revert to pure JavaScript or use some other package!

Shauna

---

<div class="post-metadata">

**Author:** ![shauna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@shauna](https://www.ruby-forum.com/u/shauna)\
**Post date:** [December 31, 2006, 8:03am UTC](https://www.ruby-forum.com/t/trouble-with-popup-window/80615/6 "2006-12-31T08:03:49Z")

</div>

Craig W. wrote:

> OK remove the id portion but I suspect that the reason that it isn’t  
> popping up a window for you is that you need the javascripts library and  
> thus need to include a layout that has \<%=  
> javascript\_include\_tag :defaults %\> in it.
> 
> Craig

I do have \<%= javascript\_include\_tag :defaults %\> in my  
application.rhtml, and all the default js libs show up in the page  
source code for my page.

I am also using rico.js. I tried removing that but it makes no  
difference to the popup window.

Shauna

---

<div class="post-metadata">

**Author:** ![shauna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@shauna](https://www.ruby-forum.com/u/shauna)\
**Post date:** [December 30, 2006, 11:27pm UTC](https://www.ruby-forum.com/t/trouble-with-popup-window/80615/7 "2006-12-30T23:27:37Z")

</div>

On Fri, 2006-12-29 at 23:29 +0100, Shauna wrote:

> Hi Craig,
> 
> I tried your permutation and the results are no different. It displays  
> the print\_list view in the same browser tab, overwriting the original  
> page. I want the original page to remain and the printable page to come  
> up in a new browser window.
> 
> By the way, my action doesn’t usea specific id - it’s just a list of the  
> entire table in the order the user has picked.

* * *

OK remove the id portion but I suspect that the reason that it isn’t  
popping up a window for you is that you need the javascripts library and  
thus need to include a layout that has \<%=  
javascript\_include\_tag :defaults %\> in it.

Craig
