I have this line of javascript to open an imagedata on a page
window.location.href = canvas.toDataURL('image/jpeg');
How can I make it invoke the save as dialog / download image
so that the visitor can save the image immediately after image load?
Currently user needs to right click>save image as
to save the image. It would be nice to automatically invoke save as dialog.
I found this that might work downloading file with save as dialog box in jsp...how to prompt user for save,view cancel dialog instead of directly opening image
But I don't know how to add response.setheader
after the page/image loads. I tried this
window.location.href = canvas.toDataURL('image/jpeg');
response.setHeader('Content-Disposition', 'attachment; filename=' + <?php the_title(); ?> + '.jpg');
But it didn't work.
Thanks