0

that is so hard to explain ....

i have that url of a js code lets call it Adcode : example.com/adcode.js

i have a js file i already injected in the main HTML page with

<script src="/a.js"></script>

i want to inject the Adcode in a.js file ..

so what to put in "a.js" , i tried :

var script document.createElement('script'); script.src = 'example.com/adcode.js'; document.body.appendChild(script)

but it didn't work ( no ad's appeared )

sorry, English is not my native language ..

notice : example.com/adcode.js is changed every time we refresh the page so i can't just copy it ...

IamPublic
  • 1
  • 1
  • 1
    Possible duplicate of [inject a script tag with remote src and wait for it to execute](http://stackoverflow.com/questions/8578617/inject-a-script-tag-with-remote-src-and-wait-for-it-to-execute) – ReGdYN Aug 07 '16 at 20:15
  • @ReGdYN thaaaaaaaaaaanks , it works now – IamPublic Aug 07 '16 at 20:25

2 Answers2

0

missing '='

var script **=** document.createElement('script');

other then that ReGdYN might be right

bresleveloper
  • 5,940
  • 3
  • 33
  • 47
0

@ReGdYN it's a duplicate of stackoverflow Question

it worked with :

(function(d, script) {
    script = d.createElement('script');
    script.type = 'text/javascript';
    script.async = true;
    script.onload = function(){
        // remote script has loaded
    };
    script.src = 'example.com/adcode.js';
    d.getElementsByTagName('body')[0].appendChild(script);
}(document));
Murilo Perrone
  • 452
  • 4
  • 7
IamPublic
  • 1
  • 1