Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As Andrew stated your first problem is probably that your doing it from file://. Try doing it from an extension.<br> After that you'll probably like to know that from Chrome 19 you can ask for the response from an xhr to be a blob.<br> Then for saving the file your better off using something like <a href="https://github.com/eligrey/FileSaver.js/" rel="nofollow noreferrer" title="FileSaver.js">FileSaver.js</a> to save the file. The iframe way works but you end up with an awful file name.<br> Here's an example to get you going.... </p> <p><strong>manifest.json</strong> </p> <pre><code>{ "name": "Download a file and click to save.", "version": "1.0", "permissions": [ "tabs", "&lt;all_urls&gt;" ], "browser_action": { "default_title": "Download a file and click to save.", "default_icon": "icon.png", "default_popup": "popup.html" }, "content_security_policy": "script-src 'self' https://raw.github.com/; object-src 'self'", "manifest_version" : 2 } </code></pre> <p><strong>popup.html</strong> </p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;!-- https://github.com/eligrey/FileSaver.js --&gt; &lt;script src="https://raw.github.com/eligrey/FileSaver.js/master/FileSaver.min.js"&gt;&lt;/script&gt; &lt;!-- https://github.com/allmarkedup/jQuery-URL-Parser/tree/no-jquery --&gt; &lt;script src="https://raw.github.com/allmarkedup/jQuery-URL-Parser/no-jquery/purl.js"&gt;&lt;/script&gt; &lt;script src="popup.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="message"&gt;Getting File.....&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>popup.js</strong> </p> <pre><code>window.URL = window.URL || window.webkitURL; var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://or.cdn.sstatic.net/chat/so.mp3', true); xhr.filename = purl('http://or.cdn.sstatic.net/chat/so.mp3').attr('file'); xhr.responseType = 'blob'; xhr.onload = function(e) { var message = document.querySelector('#message'); message.parentNode.removeChild(message); var link = document.createElement('A'); link.innerText = 'Download File'; link.href = '#'; link.addEventListener('click', saveFile, false); document.body.appendChild(link); }; xhr.onerror = function() { var message = document.querySelector('#message'); message.innerText = 'Error getting file'; this.filename = ''; } xhr.send(); saveFile = function() { saveAs(xhr.response, xhr.filename); // saveAs function is from FileSaver.js } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload