SitePoint Sponsor |
|
User Tag List
Results 1 to 13 of 13
Thread: clicking a jpeg link
-
Feb 10, 2009, 03:24 #1
clicking a jpeg link
pardon me if this is very n00bish, but i have a problem that i can't figure out.
i have a link "download image"
i want the user to be able to click that link, then have the usual "download file" box to pop up.
problem is, the links are jpegs, soo when you click the link, all it does is link to a new browser with the image at full size. (i don't want it to do this!)
any help is much appreciated!
-
Feb 10, 2009, 04:07 #2
Hi,
Is an anchor wrapped around the image? A sample of your source code would be helpful.
What you want to do is have the browser ignore the "href" attribute. You can do this with href="#". You can then fire whatever action is required with the onclick event.
-
Feb 10, 2009, 04:27 #3
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
What you're asking requires changing the content-type of the linked files on the server-side.
Normal practice is instead to advise people to right-click on the image and choose the "save link" option.
Alternatively, you could use a different file extension. An example of which is to compress the images and use zip files instead for the links.Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript
-
Feb 10, 2009, 09:13 #4
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Almost right.
You need to make your server send a new HTTP header, like this:
Code:Content-Disposition: attachment; filename=MyImage.jpg
The easiest way is often to have a server-side script wrapper to do this.Birnam wood is come to Dunsinane
-
Feb 10, 2009, 14:15 #5
i was thinking about solving the problem by using zip files, but that gives 1 more step to the viewer, and i don't really want that.
this site here does what i want to do.
http://p o o l g a.com/en/p/108 (remove spaces)
when you click on the "save" icons below the images, it pops up to save the jpeg in the download box.
-
Feb 10, 2009, 14:26 #6
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
That's because the image is at http://poolga.com/wp/310.jpg
while the save button links to http://poolga.com/down/310
The server would be returning the image with a content disposition as mentioned by AutisticCuckooProgramming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript
-
Feb 10, 2009, 18:51 #7
alright. so how do i set up my document to do that?
is it a line of code that goes in the header?
i was sifting through that text document and couldn't find what i needed
-
Feb 10, 2009, 18:54 #8
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
That depends on what server-side code that you're using.
If it's php, then the people in the php forum will have the answer for you.
As an example though, here here info from the php header page.
Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript
-
Feb 11, 2009, 00:58 #9
i'm using a css/html combo
i appreciate your help!
-
Feb 11, 2009, 01:03 #10
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You can't do this with HTML and CSS, I'm afraid. If you don't have access to a server-side programming language (PHP, .NET, JSP, ColdFusion, ...) you'll need to tweak the server to send this header. That can probably be quite tricky if you only want it to happen for certain JPEG files.
Birnam wood is come to Dunsinane
-
Feb 11, 2009, 01:25 #11
that website i posted in post 5 was html though?
-
Feb 11, 2009, 01:51 #12
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
The end result is html, but when you look at the address bar you can see that it's obviously using url rewriting.
Read this article:
A Beginner's Guide to URL RewritingProgramming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript
-
Feb 20, 2009, 14:03 #13
- Join Date
- Jun 2005
- Location
- Canada
- Posts
- 25
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The only thing I could suggest for you to do this very easily would be to have the words "Right Click this LINK and Click Save As" and have that clickable to your image.
Wow I found that link helpful! Thanks pmw57!Last edited by kabo0m; Feb 20, 2009 at 14:06. Reason: Added thanks
Bookmarks