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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Location
    Argentina
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer createElement creates error in IE6

    Hello,

    I'm trying to build a function that includes a javascript or php script into the web page by including a SCRIPT element into the HEAD element.

    the code looks like this:

    function includeScript(filePath){
    var fileExt = filePath.substring(filePath.lastIndexOf("."),filePath.length);
    var scriptType;
    switch(fileExt){
    case "js": scriptType = "text/javascript";
    break;
    case "php": scriptType = "text/php";
    break;
    }
    var scrElement = document.createElement("script");
    scrElement.setAttribute("type",scriptType);
    srcElement.setAttribute("src",filePath);
    document.documentElement.childNodes[0].appendChild(scrElement);
    }

    Do someone knows why the browser launchs an error telling that it is unable to open the window......

    Thanks and regards

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    try:

    document.getElementsByTagName('head')[0].appendChild(scrElement);
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Location
    Argentina
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot.....

    Now the browser open the document but, I don't know if it compiles the code in the external source......

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    how is your code now?
    Last edited by Kor; 07-14-2006 at 09:58 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New to the CF scene
    Join Date
    Jul 2006
    Location
    Argentina
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer

    The code is as follows:

    function includeScript(filePath){
    var d = document,fileExt = filePath.substring(filePath.lastIndexOf("."),filePath.length);
    var scriptType;
    switch(fileExt){
    case "js": scriptType = "text/javascript";
    break;
    case "php": scriptType = "text/php";
    break;
    }
    var scriptElement= d.createElement("script");
    scriptElement.setAttribute("type",scriptType);
    scriptElement.setAttribute("src",filePath);
    d.getElementsByTagName("head")[0].appendChild(scriptElement);
    }

    Now, this is in an external file called IncludeScript.js wich I include by declaring a script element with src pointing to this file. Now oce this is done, I call the function from another script tag and then I run the following function that displays the elements in the Head element.


    function displayHeadElements(){
    var h = document.getElementsByTagName("head")[0];
    document.write("<TABLE>");
    for(var i=0;i<h.childNodes.length;i++){
    var e = h.childNodes[i];
    document.write("<tr colspan=\"2\"><td>ELEMENT</td></tr>");
    document.write("<tr><td>NodeName</td><td>NodeType</td>");
    document.write("<tr>");
    document.write("<td>" + e.nodeName + "</td>");
    document.write("<td>" + e.nodeType + "</td>");
    document.write("</tr>");
    document.write("<tr colspan=\"2\"><td>ATTRIBUTES</td></tr>");
    document.write("<tr><td>AttrName</td><td>AttrValue</td></tr>");
    for(var j=0;j<e.attributes.length;j++){
    var a = e.attributes[j];
    if(a.value!=null){
    document.write("<tr>");
    document.write("<td>" + a.name +"</td>");
    document.write("<td>" + a.value + "</td>");
    document.write("</tr>");
    }
    }
    }
    }

    and I call it in the body.
    Now, this function list the included "script" element so the function works (thanks to you) but when calling a function defined in the external ".js" file included using the function the Browser throws a "An object was/is expected" error.

    If you want to try it.....

    Thanks anyway


  •  

    Posting Permissions

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