Would this script work for the job I need it to do?

Discussion in 'JavaScript' started by chriswick, Jul 21, 2007.

Thread Status:
Not open for further replies.
  1. #1
    Hello all,

    I'm trying to pass "bg_color" as a parameter into an external .js or javascript file.

    Example:

    <script type='text/javascript'>
    var bg_color = '#6666FF'
    </script>
    <script type='text/javascript' src='http://www2.domainname.com/file/file.js'></script>
    HTML:
    This is the code I tryed in the JavaScript file but it will only pick up colors on the file itself and not from where I want it to take the values from being

    var bg_color = '#6666FF'
    HTML:
    The code I have is this one, is there anything that I have missed out to make the function work?

    (function(){
    document.write("<body bgcolor= "+ bg_color + ", ");
    })()
    HTML:
    Chris
     
    chriswick, Jul 21, 2007 IP
  2. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #2
    You didn't call your function

    I didn't really understand what you said, but... Yes you can pass as a parameter to an external javascript file.

    Exemple:


    <script type='text/javascript'>
    bg_color = '#6666FF'
    </script>
    <script type='text/javascript' src='javascript.js'></script>
    HTML:
    javascript.js
    function writeBg(){
    	document.write(bg_color);
    } 
    writeBg();
    HTML:
    This is how adsense, statcounter, ewebcounter work...
     
    nabil_kadimi, Jul 21, 2007 IP
Thread Status:
Not open for further replies.