Solved

Web Page Button with Save As option

Posted on 2013-11-27
10
306 Views
Last Modified: 2013-12-27
This is the web page where I have the sample code I am working with. I want to use javascript to create a button that will allow the user to download the image they see on the screen. So far all I have been able to get is the image in a new page with no header. What I want is a "Save As" pop up option. How can I accomplish this.

http://www.mrtechnology1954.com/santaclaus/santa24.html

Thank you!

Robert
0
Comment
Question by:RobertEhinger
  • 4
  • 2
  • 2
10 Comments
 
LVL 2

Accepted Solution

by:
pinish earned 500 total points
Comment Utility
Try:-

<script>
function SaveFile(fname){
img.document.execCommand('saveas', null ,fname)
}
</script>

<iframe id="img" src="yourimage.jpg" width="(image width + 20)px" height="(image height + 25)px" scrolling="no" frameborder="0px"></iframe>


<button onclick="SaveFile('yourimage.jpg');">save as</button>
0
 

Author Comment

by:RobertEhinger
Comment Utility
That works except there is one small problem. I now have a black rectangle above the image and next to the save as button. What did I do wrong to cause that?
0
 
LVL 2

Assisted Solution

by:pinish
pinish earned 500 total points
Comment Utility
To be completely fair it is a bit of a hack and probably doesn't work in some  browsers.

Better way to do this is server side - do you have PHP or something like that available to you?  The "correct" way is to force the content type which will prompt the client to download rather than display the image - there are loads of examples to do it that way.  If you still really want a javascript button you can set the action to be the server side script which will do the same thing.
0
 
LVL 14

Expert Comment

by:jb1dev
Comment Utility
The best way  to do this really is on the server.

Some other options are the HTML5 download attribute, that is for link, not button:
http://davidwalsh.name/download-attribute
Though that doesn't work on my browser. (Firefox, Ubuntu)

You could also base64 encode the image. Though your image is huge. See example:
http://jsfiddle.net/5whKM/

I've seen people claim they can extract the the img src and change the type to data:application/octet-stream forcing the browser to open a Save As dialog, but again I cannot recreate this in my env.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:RobertEhinger
Comment Utility
I have Dreamweaver CS4 which is what I used to build all the pages associated with this site. I can easily add a button to the page but I don't know where to go to get the appropriate actions that I want associated with the button.
0
 
LVL 14

Expert Comment

by:jb1dev
Comment Utility
I think what pinish and I are both saying is that the proper way to do this is to use a server side script to set the content type and serve the image.

Do you have php available on your server?

Any javascript actions you can associate with the button are client side scripts only and will not actually do what you are looking for.
0
 

Author Comment

by:RobertEhinger
Comment Utility
the server where this will ultimately reside does not have php available. Are there any other options? If I have to use the javascript how can I control the size of the image and is there a way to have it centered on the screen when it is opened?
0
 

Author Comment

by:RobertEhinger
Comment Utility
The owner of the web site decided he just needed for the visitor to be able to print the image with no header. That has been accomplished so the problem is resolved.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Understanding Trigger in Jquery 10 24
Modify Table Width 6 13
Embarcadero WebBroker REST server endpoint parameters 2 13
onOpen 14 27
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now