Simple question. Is it possible to generate a link like <a href="http://www.google.com" target="_blank" >google</a> with the link_to function ? Thanks
On 3.1.2006, at 14.13, oo00oo wrote:> Simple question. Is it possible to generate a link like > > <a href="http://www.google.com" target="_blank" >google</a> > > with the link_to function ?Yes: "It?s also possible to pass a string instead of an options hash to get a link tag that just points without consideration. If nil is passed as a name, the link itself will become the name." [1] So, <%= link_to "google", "http://www.google.com" %> should do the job. //jarkko [1] http://api.rubyonrails.com/classes/ActionView/Helpers/ UrlHelper.html#M000332 -- Jarkko Laine http://jlaine.net http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2363 bytes Desc: not available Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060103/6d5bede9/smime.bin
Thanks <%= link_to "google", "http://www.google.com" , {:target => "_blank" }%> works. I add ":target" for test and this is working. But I can''t find ":target" in the link_to documentation at UrlHelper.html Is it possible to find a most exhaustive list of ":property" possible ? Yes: "It’s also possible to pass a string instead of an options hash to get a link tag that just points without consideration. If nil is passed as a name, the link itself will become the name." [1] So, <%= link_to "google", "http://www.google.com" %> should do the job. //jarkko [1] http://api.rubyonrails.com/classes/ActionView/Helpers/ UrlHelper.html#M000332 -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi, ooOOoo, as many rails functions the link_to function takes parameters that are not mandatory for the function as an optional hash. You might write anything into this hash. So the answer to your question of a list of possible :properties would be ''endless''. See for example: <%= link_to "google", "http://www.google.com" , { :foo => "bar" } %> producing <a href="http://www.google.com" foo="bar">google</a> You might have a look at http://www.w3schools.com/tags/tag_a.asp for key => value - pairs that make ''sense''. Regards Jan oo00oo wrote:> Thanks > > <%= link_to "google", "http://www.google.com" , {:target => "_blank" }%> > > works. I add ":target" for test and this is working. But I can''t find > ":target" in the link_to documentation at UrlHelper.html > > Is it possible to find a most exhaustive list of ":property" possible ? > >> >> Yes: >> >> "It?s also possible to pass a string instead of an options hash to >> get a link tag that just points without consideration. If nil is >> passed as a name, the link itself will become the name." [1] >> >> So, <%= link_to "google", "http://www.google.com" %> should do the job. >> >> //jarkko >> >> [1] http://api.rubyonrails.com/classes/ActionView/Helpers/ >> UrlHelper.html#M000332 >> >> -- >> Jarkko Laine >> http://jlaine.net >> http://odesign.fi >> >>------------------------------------------------------------------------ >> >>_______________________________________________ >>Rails mailing list >>Rails@lists.rubyonrails.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >
So you know, target="_blank" is not valid XHTML. I recommend reading about using the rel="external" tag if you so desire to popup a new window. Here is some sample JavaScript I have in my default JS library code I use in such a case to ensure XHTML compliancy: function externalLinks() { if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i=0; i<anchors.length; i++) { var anchor = anchors[i]; if (anchor.getAttribute("href") && anchor.getAttribute("rel") ="external") { anchor.target = "_blank"; } } } window.onload = externalLinks; You can find fill documentation for the url_for method at: http://www.railsmanual.org/class/ActionController%3A%3ABase#meth_url_for In addition, there are 3 special options for the html_options parameter with link_to, outlined here: http://www.railsmanual.org/module/ActionView%3A%3AHelpers%3A%3AUrlHelper#met h_link_to Regards, Nathaniel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Nathaniel S. H. Brown http://nshb.net ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of oo00oo > Sent: January 3, 2006 4:13 AM > To: rails@lists.rubyonrails.org > Subject: [Rails] link_to an external url ? > > Simple question. Is it possible to generate a link like > > <a href="http://www.google.com" target="_blank" >google</a> > > with the link_to function ? > > Thanks > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
:target is a HTML (although non XHTML compliant) tag. All other HTML attributes are valid tags such as :onmouseover, :onclick, :class, :id, etc can be used. They are not documented as you should reference W3 for what HTML tags are truly valid. -Nb ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Nathaniel S. H. Brown http://nshb.net ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of oo00oo > Sent: January 3, 2006 4:39 AM > To: rails@lists.rubyonrails.org > Subject: Re: [Rails] link_to an external url ? > > Thanks > > <%= link_to "google", "http://www.google.com" > <http://www.google.com> , {:target => "_blank" }%> > > works. I add ":target" for test and this is working. But I > can''t find ":target" in the link_to documentation at UrlHelper.html > > Is it possible to find a most exhaustive list of ":property" > possible ? > > > > Yes: > > "It''s also possible to pass a string instead of an > options hash to get a link tag that just points without > consideration. If nil is passed as a name, the link itself > will become the name." [1] > > So, <%= link_to "google", "http://www.google.com" > <http://www.google.com> %> should do the job. > > //jarkko > > [1] > http://api.rubyonrails.com/classes/ActionView/Helpers/ > UrlHelper.html#M000332 > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > > > ________________________________ > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >
perhaps :popup => true without sizes options is more simple than js ?>So you know, target="_blank" is not valid XHTML. I recommend reading about >using the rel="external" tag if you so desire to popup a new window. > >Here is some sample JavaScript I have in my default JS library code I use in >such a case to ensure XHTML compliancy: > >function externalLinks() { > if (!document.getElementsByTagName) return; > var anchors = document.getElementsByTagName("a"); > for (var i=0; i<anchors.length; i++) { > var anchor = anchors[i]; > if (anchor.getAttribute("href") && anchor.getAttribute("rel") =>"external") { > anchor.target = "_blank"; > } > } >} >window.onload = externalLinks; > > >
Popus tend to lack all the toolbars due to the nature of what a popup is. Unless you stack it with options to match the feature set across all browsers natively you will find that the JavaScript below may be a more viable option. Search engines do not appreciate popup links and have a hard time following them for indexing, so you might be better off using such a tactic as mentioned via the JavaScript rel="external" option. -Nb ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Nathaniel S. H. Brown http://nshb.net ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of oo00oo > Sent: January 3, 2006 7:08 AM > To: rails@lists.rubyonrails.org > Subject: Re: [Rails] link_to an external url ? > > perhaps :popup => true without sizes options is more simple than js ? > > > >So you know, target="_blank" is not valid XHTML. I recommend reading > >about using the rel="external" tag if you so desire to popup > a new window. > > > >Here is some sample JavaScript I have in my default JS > library code I > >use in such a case to ensure XHTML compliancy: > > > >function externalLinks() { > > if (!document.getElementsByTagName) return; > > var anchors = document.getElementsByTagName("a"); > > for (var i=0; i<anchors.length; i++) { > > var anchor = anchors[i]; > > if (anchor.getAttribute("href") && > anchor.getAttribute("rel") > >=> >"external") { > > anchor.target = "_blank"; > > } > > } > >} > >window.onload = externalLinks; > > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >