Ok, I have a need to load the scriptaculous files inside a ''try...catch'' block in order to degrade gracefully on older browsers (IE 5.0 is one I have to support, unfortunately). I tried this: try { document.write(''<script type="text/javascript" src="/javascript/prototype.js"></script>''); document.write(''<script type="text/javascript" src="/javascript/scriptaculous.js"></script>''); } catch (e) {}; Unfortunately that makes Mozilla display this in the document: '') } catch (e) {}; Anyone got any other ideas I could try? I wouldn''t care, except that IE 5.0 throws like 5 javascript errors for just including prototype.js and scriptaculous.js. My boss isn''t gonna let that fly. I could do manual browser detection, but I''d rather have a more generic mechanism. Greg
Martin Bialasinski
2005-Dec-27 17:50 UTC
Re: can I load javascript inside a ''try'' block?
On 27/12/05, Gregory Hill <Gregory_Hill-l9nu40+TWxQ@public.gmane.org> wrote:> document.write(''<script type="text/javascript" > src="/javascript/prototype.js"></script>'');> Unfortunately that makes Mozilla display this in the document: > '') } catch (e) {};You may not include a ETAGO (end tag) in the script. document.write(''<script type="text/javascript" src="/javascript/prototype.js"><\/script>''); If it is about IE only, I would do this with conditional comments. <![if gt IE 5]> <script type="text/javascript"> src="/javascript/prototype.js"></script> <![endif]> will include the script in IE > 5 and any other browser. Martin
> You may not include a ETAGO (end tag) in the script. > > document.write(''<script type="text/javascript" > src="/javascript/prototype.js"><\/script>'');Ah, duh!! Thanks for pointing that out, I hadn''t considered that. Unfortunately, putting that in an try...catch block still throws javascript errors in IE 5.0. I guess it does the try on writing the script tag, but then parses the contents of the file outside the realm of the try block. Oh well.> > If it is about IE only, I would do this with conditional comments. > > <![if gt IE 5]> > <script type="text/javascript">src="/javascript/prototype.js"></script>> <![endif]> > > will include the script in IE > 5 and any other browser.That''s cool; I had never heard of that. I''m guessing it''s an IE only thing, right? Any other browser will just blindly load the file, right? Greg