SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy problem with appendChild and <SCRIPT>

    hello again. I have a new problem, but this time with both browsers.

    Im trying to load dynamically an SCRIPT. I use the following code:

    Code:
    oScript.src = "http://feeds.feedburner.com/~s[...]";
    oScript.type = "text/javascript";
    oScript.charset = "utf-8";
    
    answer.childNodes[0].appendChild(oScript);
    well, when I run my site, and after loading the script, that does not appear in the position of "answer.childNodes[0]" as a child. Instead of that it opens in the "whole" window, like a child of document directly and deleting all the content of the window.


    that happens to me with every script that I try to load dYnamically (weather forecast, google search...) so I cant do anything dynamic

    do you know what Im doing wrong???

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to show more code to clarfiy what answer is. Also show parts of the HTML you are appending to

  3. #3
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, the all code is this.

    Code:
    <html>
        <head>
            <title>Style Example</title>
            	
            <script type="text/javascript" src="js/detect.js"></script>
    				<script type="text/javascript" src="js/eventutil.js"></script>
            <script type="text/javascript">
                function showTip() {
                    var oEvent = EventUtil.getEvent();
                    var oDiv = document.getElementById("divTip1");
                    oDiv.style.visibility = "visible";
                    oDiv.style.left = oEvent.clientX + 5;
                    oDiv.style.top = oEvent.clientY + 5;
                    
                    var oScript = document.createElement("script");
    				        oScript.src = "ejemplo.js";
    				        oScript.type = "text/javascript";
    				        oScript.charset = "utf-8";
    				        oDiv.appendChild(oScript);
                }
    
                function hideTip() {
                    var oDiv = document.getElementById("divTip1");
                    oDiv.style.visibility = "hidden";
                }
                
    
            </script>
        </head>
        <body>
            <p>Move your mouse over the red square.</p>
            <span id="div1">Opciones</span>
    
             <div id="divTip1" 
                  style="background-color: yellow; position: absolute; visibility: hidden; padding: 5px">
                <span style="font-weight: bold">Custom Tooltip</span><br />
                More details can go here. <span id="cerrar"> cerrar</span>
             </div>
             
                     <script type="text/javascript">
                         
                var divs = document.getElementById('div1');
                var divtip = document.getElementById('cerrar');
                EventUtil.addEventHandler(divs, 'click', showTip);
                EventUtil.addEventHandler(divtip, 'click', hideTip);
             </script>
        </body>
    </html>
    ive seen that a lot of people have this problem all over internet but I could not find the solution.

    "ejemplo.js" contains "document.write('hola')";

    what happens when I click on div1?

    - Firefox: the tip is shown one millisecond and suddenly the content of the whole window disappear and the "hola" replaces it.
    - IE: the tip is shown but the script is not executed.


  4. #4
    SitePoint Enthusiast Tygatur's Avatar
    Join Date
    Apr 2006
    Location
    Germany
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If document.write() is executed after the page has been loaded then the content of the page is emptied and an "open document" is created that gets its content from document.write().
    So use the DOM methods instead of document.write();

    I don't understand your script completely but what i can tell you is that FF can't change the src attribute of the script tag. This is a known bug.
    Instead use DOM to kill the <script> Tag and then create a new <script> Tag with a src="" Attribute of your choice.
    to code or not to code ?
    that's too much of a question for a signature.


Bookmarks

Posting Permissions

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