Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Feb 2009
    Posts
    18
    Member #
    18405
    This actually more of a javascript/PHP problem, but I think the problem is more of the javascript so I'll post here.

    I want to run a script that contains nested script tags that will call to a php script and then return some javascript to be executed. Here is what I have so far:

    <script type="text/javascript">
    function function_name(var1,var2,var3....)
    {

    SOME CODE....

    if(expression)
    {
    SOME CODE...

    }
    else
    {
    SOME CODE...
    document.write("<script type='text/javascript' src='blah.php'><\/script>"
    }



    }
    </script>


    The problem with this is that when the function executes and the else statement is triggered, it wipes my page clean and THEN executed the nested code. This cannot happen. The resulting code from the PHP is supposed to manipulate the page content. Anyone know a way around this?

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Try this instead:

    Code:
    else
    {
        // ...
    
        var elt = document.createElement("script");
        elt.type = "text/javascript";
        elt.src = "blah.php";
    
        document.getElementsByTagName('head')[0].appendChild(elt);
    }

  4. #3
    Junior Member
    Join Date
    Feb 2009
    Posts
    18
    Member #
    18405
    Quote Originally Posted by Shadowfiend
    Try this instead:

    Code:
    else
    {
        // ...
    
        var elt = document.createElement("script");
        elt.type = "text/javascript";
        elt.src = "blah.php";
    
        document.getElementsByTagName('head')[0].appendChild(elt);
    }
    Great! Thanks man!

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    So it worked? Sweet :-D


Remove Ads

Posting Permissions

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

Search tags for this page

nested script tags

Click on a term to search for related topics.
All times are GMT -6. The time now is 06:04 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com