Document.write issues
by
, 05-16-2009 at 11:48 PM (25195 Views)
The Ajax Includes Script given at http://www.dynamicdrive.com/dynamici...axincludes.htm uses document.write for including external content. Advantage: you don't have to explicitly bring the js belonging to the external file(s) to the main page. But beware the results in certain cases! In IE, (external) scripts added to the page using document.write are not run until after the document.write that adds them has finished. Non-IE browsers will run them straight away. Sowhere bla.js contains document.write('drive.'), produces dynamic.drive.com. in non-IE, but dynamic.com.drive. in IE. So in IE, document.write may put external javascript at the wrong place.Code:<script type="text/javascript"> document.write('dynamic.'); document.write('<script src="bla.js"><\/script>'); document.write('com.'); </script >
That is indeed what happens if we use the script given at http://www.dynamicdrive.com/dynamici...axincludes.htm to include the menu-files of http://www.dynamicdrive.com/dynamici...menu/index.htm. Try for yourself. Things won't work in IE. (The only way to get out of this situation is to replace the external js belonging to the files_to_be_included with internal js).
Of course, the cases mentioned here are only illustrations of a more general problem that we may encounter if we use document.write for including external content in an 'unwise' way.
===
Arie Molendijk.