The Download Attribute a[download]
The Download Attribute a[download]
syntax:
<a href="../../dr-evil-802.jpg" download="evil">download me</a>
window.addEventListener('load', function (e) { var MIME_TYPE = 'text/x-vcard'; var link = document.getElementById('virtual-file-link'); var contact = document.getElementById('contact'); var obj = navigator.microformats.get('hCard', contact); obj = obj.microformats.vcard[0]; var name = obj.fn.replace(/ /gi, '_'); var vcard = hCardtovCard(obj); window.URL = window.webkitURL || window.URL; window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder; var builder = new window.BlobBuilder(); builder.append(vcard); link.download = name + '.vcf'; link.href = window.URL.createObjectURL(builder.getBlob(MIME_TYPE)); });DownloadUrl Support - Dragging files to the desktop
var link = document.getElementById('draglogo'); link.addEventListener("dragstart", function (e) { e.dataTransfer.setData("DownloadURL", "image/png:logo.png:http://glennjones.net/images/logo16.png"); });Offer files for download in HTML5: a[download]
The new attribute download for <a> tags allows one to offer a file for download – instead of displaying it in the browser. Previously. Normally, when you click on an <a> tag, the web browser visits the file it refers to. Sometimes, you instead want the file to be downloaded. Most browsers usually ask the user to confirm before starting the download. Previously, you had to send the following HTTP header to make that happen.Content-Disposition: attachment; filename=my-icon.pngNow. The new attribute download ensures that a file is downloaded and not displayed.<a href="http://example.com/3zw1456.png" download="my-icon.png" >download me</a>Giving the attribute a value allows you to control the name of the file that is saved to disk. Use case. This feature is especially useful if you are working with URLs coming from Blob instances (which include File instances in the user’s file system) and FileEntry instances (in browser-local sandboxed file systems). With download, their data becomes downloadable.
http://chunghe.googlecode.com/svn/trunk/experiment/html5.download.attribute/index.htm
沒有留言:
張貼留言