Forum: Ruby on Rails New Browser Window using AJAX

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F677fa685a2cfe8aff31f161062db3d3?d=identicon&s=25 David (Guest)
on 2009-03-03 02:04
(Received via mailing list)
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.
91a72b0ad3e43e3ef3a31816667ec694?d=identicon&s=25 bill walton (Guest)
on 2009-03-03 02:48
(Received via mailing list)
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 Fauser's .pdf off O'Reilly.

HTH,
Bill
Aad37b5f7116c8d1f547d23b37566032?d=identicon&s=25 Greg Donald (destiney)
on 2009-03-03 06:02
(Received via mailing list)
On Mon, Mar 2, 2009 at 7:03 PM, David <dlynam@gmail.com> 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 Donald
http://destiney.com/
F677fa685a2cfe8aff31f161062db3d3?d=identicon&s=25 Dave L (Guest)
on 2009-03-03 13:09
(Received via mailing list)
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?
Aad37b5f7116c8d1f547d23b37566032?d=identicon&s=25 Greg Donald (destiney)
on 2009-03-03 21:28
(Received via mailing list)
On Tue, Mar 3, 2009 at 6:08 AM, Dave L <dlynam@gmail.com> 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 Donald
http://destiney.com/
7ce426fb7115fd6ef8e9aa2c353e0617?d=identicon&s=25 David Franklin (novus)
on 2009-03-13 16:36
(Received via mailing list)
Greg - this "works" but is flagged by popup blockers on IE and
Firefox.  Any thoughts on methods around this?
170e2a48994775e4c298c302e6814f81?d=identicon&s=25 Starr Horne (Guest)
on 2009-03-13 20:27
(Received via mailing list)
> 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 Horne
My blog: http://starrhorne.com
Check out my Helpdesk RailsKit: http://railskits.com/helpdesk/
This topic is locked and can not be replied to.