View Full Version : JavaScript printing other <script> tags

03-15-2005, 04:47 AM
I'm writing a website component (java based) for websites, but In internet explorer, when I use Javascript to write another <script> tag, it doesnt show up in internet explorer.

step 1: someone puts <script ... ... src="http://www.mySite.com/component.php">

step 2: (component.php's output)
document.writeln('<script ... ... src="http://www.mySite.com/runComp.php?website='+document.URL+'&blah=blah">');

step 3: (runComp.php's output)
document.writeln('<table><tr> ... ... blah blah blah ... ... </tr></table>';

I do this because alot of features requre the pages URL and such, but only javaScript has the scope to give the documents true URL. I can make the JAVA write an IFRAME, but that would be nightmarish with complications.

EDIT: this page is perfect for what I mean: http://www.webmasterworld.com/forum91/342.htm

03-15-2005, 01:25 PM
You aren't giving quite enough information. We are only interested in the page that gets sent to the user, and the actual script that doesn't work.

If the original script is embedded in the HTML page, you need to escape "</" to "<\/" inside the script element. Even less strict parsers (browsers today fall in this category) will need to escape the "</script>" sequence, however.

If the script is in a separate file, there's no need to do such catering to the HTML parsers.

03-15-2005, 02:58 PM
Use the below function to load any .js file from javascript. It is DOM way of doing things.

function loadJSContent(file){
var head = document.getElementsByTagName("head")[0];
script = document.createElement('script');
script.src = file;
script.type = 'text/javascript';

Example usage below...


Hope this tiny function will be of some help to you...

Have a nice day :)