New Browser Window using AJAX

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.

Hi David,

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

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 - this "works" but is flagged by popup blockers on IE and Firefox. Any thoughts on methods around this?

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