I''m having trouble writing the required javascript to open a link in a new browser window in Rails3. Previously, in rails2.3.x I could just do: link_to "foo", foo_path(foo), :popup => true But now in Rails3, this option has been deprecated and the only other way I can imagine doing this would be to use link_to_function but that has also been nuked so I can''t figure this out. Can anyone give me some pointers please? Thanks PS: I''m specifically looking to open a new browser-window, as opposed to a modal-box or a jquery dialogue as I need it to stay alive whilst the user continues to browse the site... -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Just add to your link: :target => ''_blank'' In your exemple, made this: link_to "foo", foo_path(foo), :target => ''_blank'' Steve Murdoch wrote:> I''m having trouble writing the required javascript to open a link in a > new browser window in Rails3. > > Previously, in rails2.3.x I could just do: > > link_to "foo", foo_path(foo), :popup => true > > But now in Rails3, this option has been deprecated and the only other > way I can imagine doing this would be to use link_to_function but that > has also been nuked so I can''t figure this out. > > Can anyone give me some pointers please? > > Thanks > > PS: I''m specifically looking to open a new browser-window, as opposed > to a modal-box or a jquery dialogue as I need it to stay alive whilst > the user continues to browse the site...-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Another option is to use the Rails 3 unobtrusive way of event delegating those links: - Add an attribute "data-popup" to your link_to if you want it to open in a new window With the jquery adapter, add to application.js inside the document ready handler: $(''a[data-popup]'').live(''click'', function(e) { window.open($(this).href); e.preventDefault(); }); With the prototype adapter, use this code inside the document ready handler: document.on("click", "a[data-popup]", function(event, element) { if (event.stopped) return; window.open($(element).href); event.stop(); }); Rails 3 has been all about separating content from behavior and falling back to target _blank is like bragging about how economic your brand new car is on paper and then driving it with the rev all the way into the red zone all the time. On 16 Jul 2010, at 14:29, Kirk Patrick wrote:> Just add to your link: > > :target => ''_blank'' > > In your exemple, made this: > > link_to "foo", foo_path(foo), :target => ''_blank'' > > Steve Murdoch wrote: >> I''m having trouble writing the required javascript to open a link >> in a >> new browser window in Rails3. >> >> Previously, in rails2.3.x I could just do: >> >> link_to "foo", foo_path(foo), :popup => true >> >> But now in Rails3, this option has been deprecated and the only other >> way I can imagine doing this would be to use link_to_function but >> that >> has also been nuked so I can''t figure this out. >> >> Can anyone give me some pointers please? >> >> Thanks >> >> PS: I''m specifically looking to open a new browser-window, as opposed >> to a modal-box or a jquery dialogue as I need it to stay alive whilst >> the user continues to browse the site... >Best regards Peter De Berdt -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
hey, never noticed this reply~ I ended up installing the prototype_legacy helper plugin and good old link_to_function to fix the problem but I really do prefer your suggestion so I will give that a go - thanks a lot. steve On Jul 16, 2:56 pm, Peter De Berdt <peter.de.be...-LPO8gxj9N8aZIoH1IeqzKA@public.gmane.org> wrote:> Another option is to use the Rails 3 unobtrusive way of event > delegating those links: > > - Add an attribute "data-popup" to your link_to if you want it to open > in a new window > > With the jquery adapter, add to application.js inside the document > ready handler: > > $(''a[data-popup]'').live(''click'', function(e) { > window.open($(this).href); > e.preventDefault(); > }); > > With the prototype adapter, use this code inside the document ready > handler: > > document.on("click", "a[data-popup]", function(event, element) { > if (event.stopped) return; > window.open($(element).href); > event.stop(); > }); > > Rails 3 has been all about separating content from behavior and > falling back to target _blank is like bragging about how economic your > brand new car is on paper and then driving it with the rev all the way > into the red zone all the time. > > On 16 Jul 2010, at 14:29, Kirk Patrick wrote: > > > > > Just add to your link: > > > :target => ''_blank'' > > > In your exemple, made this: > > > link_to "foo", foo_path(foo), :target => ''_blank'' > > > Steve Murdoch wrote: > >> I''m having trouble writing the required javascript to open a link > >> in a > >> new browser window in Rails3. > > >> Previously, in rails2.3.x I could just do: > > >> link_to "foo", foo_path(foo), :popup => true > > >> But now in Rails3, this option has been deprecated and the only other > >> way I can imagine doing this would be to use link_to_function but > >> that > >> has also been nuked so I can''t figure this out. > > >> Can anyone give me some pointers please? > > >> Thanks > > >> PS: I''m specifically looking to open a new browser-window, as opposed > >> to a modal-box or a jquery dialogue as I need it to stay alive whilst > >> the user continues to browse the site... > > Best regards > > Peter De Berdt-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I had to add [0] otherwise it didnt work. Good luck Dave $(''a[data-popup]'').live(''click'', function(e) { window.open($(this)[0].href); e.preventDefault(); }); stephenjamesmurdoch wrote:> > I''m having trouble writing the required javascript to open a link in a > new browser window in Rails3. > > Previously, in rails2.3.x I could just do: > > link_to "foo", foo_path(foo), :popup => true > > But now in Rails3, this option has been deprecated and the only other > way I can imagine doing this would be to use link_to_function but that > has also been nuked so I can''t figure this out. > > Can anyone give me some pointers please? > > Thanks > > PS: I''m specifically looking to open a new browser-window, as opposed > to a modal-box or a jquery dialogue as I need it to stay alive whilst > the user continues to browse the site... > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > >-- View this message in context: http://old.nabble.com/Rails3%3A-open-link-in-new-window-tp29179554p30147197.html Sent from the RubyOnRails Users mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.