Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaScript printing other <script> tags

    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
    Last edited by Raraken; 03-15-2005 at 04:52 AM.

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    New Coder
    Join Date
    Aug 2004
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use the below function to load any .js file from javascript. It is DOM way of doing things.

    Code:
    function loadJSContent(file){
    	var head = document.getElementsByTagName("head")[0];
    	script = document.createElement('script');
    	script.src = file;
    	script.type = 'text/javascript';
    	head.appendChild(script)
    }
    Example usage below...

    Code:
    loadJSContent("myexternaljavascriptfile.js");
    Hope this tiny function will be of some help to you...

    Have a nice day

    Afru.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •