1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Call 2 javascript files into one

Discussion in 'HTML & JavaScript' started by SeLecTeD, Jan 8, 2015.

  1. SeLecTeD

    SeLecTeD Regular Member

    Joined:
    Mar 21, 2010
    Messages:
    260
    Likes Received:
    37
    I've got these 2 redirect codes from JuicyADS.

    Code:
    <script type="text/javascript">juicy_code='XXX';</script><script type="text/javascript" src="http://ads.juicyads.com/jsclients/jac.js" charset="utf-8"></script>
    
    
    <script type="text/javascript" src="http://ads.juicyads.com/jsclients/jam_min.js"></script>
    <script type="text/javascript">window.onload=check_mobile(XXX,XXX)</script>

    How can I merge this html code into one .js file ?

    I want to call this code in one line: <script type="text/javascript" src="http://mydomains.com/myfile.js"></script>

    Thanks guys !
     
  2. bartosimpsonio

    bartosimpsonio Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 21, 2013
    Messages:
    12,477
    Likes Received:
    11,182
    Occupation:
    CHEAP
    Location:
    DATASETS
    Home Page:
    Save them both to your hard drive, then under linux you would do:

    cat jac.js jam.js > myfile.js

    echo "<script type=\"text/javascript\">window.onload=check_mobile(XXX,XXX)</script>" >> myfile.js


    You can get linux tools for windows, it's called cygwin.
     
  3. SeLecTeD

    SeLecTeD Regular Member

    Joined:
    Mar 21, 2010
    Messages:
    260
    Likes Received:
    37
    I do not want to cache them down on my local, because they are dynamic files (other people adding lines/deleting lines)...
    I don't know how to call those files in a js one...
     
  4. ttrox

    ttrox Regular Member

    Joined:
    Jun 28, 2013
    Messages:
    217
    Likes Received:
    76
    Sure, you can, although it's not such as "importing" a new one.

    Use the following:

    Code:
    var script   = document.createElement("script");
    script.type  = "text/javascript";
    script.src   = "http://ads.juicyads.com/jsclients/jam_min.js";
    document.body.appendChild(script);
     
  5. bartosimpsonio

    bartosimpsonio Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 21, 2013
    Messages:
    12,477
    Likes Received:
    11,182
    Occupation:
    CHEAP
    Location:
    DATASETS
    Home Page:
    You mentioned you wanted to call 2 Js's into one. I have no idea what you're trying to do. ttrox's solution is the same as having a HTML file with the script tags in it.
     
  6. SeLecTeD

    SeLecTeD Regular Member

    Joined:
    Mar 21, 2010
    Messages:
    260
    Likes Received:
    37
    I basically want to merge them into one .js file.

    So my .js file will be like:
    Code:
    juicy_code='XXX';
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://ads.juicyads.com/jsclients/jam_min.js"; 
    document.body.appendChild(script);
    
    window.onload=check_mobile(XXX,XXX)
    var script = document.createElement("script1");
    script.type = "text/javascript";
    script.src = "http://ads.juicyads.com/jsclients/jac.js";
    document.body.appendChild(script1);
    
     
  7. ttrox

    ttrox Regular Member

    Joined:
    Jun 28, 2013
    Messages:
    217
    Likes Received:
    76
    I don't know about the check_mobile function, where it's called from. I also do not know why you would want to do this, but that should work out for what you said.
     
  8. SeLecTeD

    SeLecTeD Regular Member

    Joined:
    Mar 21, 2010
    Messages:
    260
    Likes Received:
    37
    I want to do this because on the website I will post this code they remove "window.onload=check_mobile(XXX,XXX)" and juicy keywords. I am trying to find a method to avoid this...