in my rails app, i have got one URL (http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=code&chld=H|0) in Javascript
view.html.erb
<%= link_to "QR","#", :onclick => "showCode();"%>in my rails app, i have got one URL (http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=code&chld=H|0) in Javascript
view.html.erb
<%= link_to "QR","#", :onclick => "showCode();"%>in my rails app, i have got one URL (http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=code&chld=H|0\) in Javascript
view.html.erb
<td><%= link_to "QR","#", :onclick => "showCode();"%></td>
<script type="text/javascript"> var imageURL; var showCode = function () { imageURL = "http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=code&chld=H|0"; $("#qr").html("<a href="+imageURL+" class='btn btn-primary pull-left'>Save</a>"); } </script> <div id="qr">
</div>
I need to download this image via click this Save button, I have use this way, But it will prompt one window, not downloading Is there any way to do this?
If you want a link to download a file from JavaScript, handle the onclick event and return a full page redirect to the file. It won't actually navigate the page to the new URL unless the URL is something that a browser can actually show (the file will just download). You mention an image -- you will probably need to set Rails to send this file as an attachment, since the browser will believe that it can handle an image. Some browsers are unwilling to be led, though, and you will still show the image. In that case, I find that Zipping the file is a great way to force the issue.
Walter