<!DOCTYPE html> <html> <head> </head> <body> <h1>Test page</h1> <p>Hello!</p> <script type="text/javascript"> var dummyscript = document.createElement('script'); // Register error function where the file does not exist. dummyscript.onerror = function() { if (dummyscript.onerror) alert("The file does not exist."); } // Append some random data to the file name so that the browser cache doesn't serve an old result. dummyscript.src = "file:///C:/Temp/testfile?" + new Date().getTime() + Math.floor(Math.random() * 1000000); // Load dummy script document.body.appendChild(dummyscript); </script> </body> </html>
But, the web browser displays "Not allowed to load local resource: file:///C:/Temp/testfile?~~~~~~".