Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking an image to an external url

I'm trying to link an image to an external URL from my index.html.erb page but it's not working. Any suggestions?

<%= link_to image_tag "facebook.png",  "http://www.facebook.com"  %>

I am also trying to link a 'send-to-friend' email image - so when a user clicks it, their email client will open automatically with a pre-written title and message ready to send. Can anyone help with this one?

like image 621
ubique Avatar asked May 23 '11 20:05

ubique


People also ask

How do you link an image to an external website?

Complete HTML/CSS Course 2022 To use image as a link in HTML, use the <img> tag as well as the <a> tag with the href attribute. The <img> tag is for using an image in a web page and the <a> tag is for adding a link. Under the image tag src attribute, add the URL of the image.

Can you add a URL link to a JPG?

To create a clickable image online, all you need is a JPG file and a website address (the URL). Just as you can add a link to any text on a web page or Word document, you can add a link to any image file, including JPGs, PNGs and GIFs.


1 Answers

It may be thinking the url is a second parameter to the image_tag method rather than to the link_to method, so wrap that up the image_tag parameters in parentheses to avoid confusion:

<%= link_to image_tag("facebook.png"), "http://www.facebook.com" %>
like image 70
Dylan Markow Avatar answered Sep 27 '22 22:09

Dylan Markow