Check if a file exists locally using JavaScript only

Your question is ambiguous, so there are multiple possible answers depending on what you’re really trying to achieve. If you’re developping as I’m guessing a desktop application using Titanium, then you can use the FileSystem module’s getFile to get the file object, then check if it exists using the exists method. Here’s an example taken … Read more

Play audio local file with html

You set the src attr directly on the audio element. fiddle var $audio = $(‘#myAudio’); $(‘input’).on(‘change’, function(e) { var target = e.currentTarget; var file = target.files[0]; var reader = new FileReader(); console.log($audio[0]); if (target.files && file) { var reader = new FileReader(); reader.onload = function (e) { $audio.attr(‘src’, e.target.result); $audio.play(); } reader.readAsDataURL(file); } }); <script … Read more

Allow Google Chrome to use XMLHttpRequest to load a URL from a local file

Using –disable-web-security switch is quite dangerous! Why disable security at all while you can just allow XMLHttpRequest to access files from other files using –allow-file-access-from-files switch? Before using these commands be sure to end all running instances of Chrome. On Windows: chrome.exe –allow-file-access-from-files On Mac: open /Applications/Google\ Chrome.app/ –args –allow-file-access-from-files Discussions of this “feature” of … Read more

How can I create a link to a local file on a locally-run web page?

You need to use the file:/// protocol (yes, that’s three slashes) if you want to link to local files. <a href=”file:///C:\Programs\sort.mw”>Link 1</a> <a href=”file:///C:\Videos\lecture.mp4″>Link 2</a> These will never open the file in your local applications automatically. That’s for security reasons which I’ll cover in the last section. If it opens, it will only ever open … Read more