Robert said the following on 3/22/2006 4:46 PM:
Randy Webb wrote: Robert said the following on 3/22/2006 10:29 AM: One other question is if it is possible to include a javascript file,
but not getting an error about it if this file does not exist (in
IE6, Firefox and other modern browsers)?
If you try to load an external file in IE6 that doesn't exist then
about 95% of the time you are going to get an "Invalid Character"
syntax error.
Yes I know, that's why I ask :)
It gives the same behavior if you try to dynamically create the script
element as well:
oScript = document.createElement('script');
oScript.src='fakeJSFile.js';
document.getElementsByTagName('head')[0].appendChild(oScript);
Invalid Character error.
You could try retrieving the file with an XMLHTTPRequest object but that
seems like trying to use a sledgehammer to install trim in your house -
overkill.
Typically, you will end up better off not trying to cope with it and let
the error message be an indication of filename/path problems to the
author. If you are retrieving the files from another server, retrieve
them using your own server and then serve it to the browser. If the file
doesn't exist on the remote server, then your server can let the browser
know that and the user never gets an error from a non-existent file.
--
Randy
comp.lang.javascript FAQ -
http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/