Why is script.onload not working in a Chrome userscript?
I want to load another script file, in a site, using a userscript. But, the js.onload event doesn't work correctly. The userscript file: // ==UserScript== // @name Code highlight // @description Test // @include http://localhost/* // @version 1.0 // ==/UserScript== var js = document.createElement('script'); js.src = "http://localhost/test/js/load.js"; document.getElementsByTagName("head")[0].appendChild(js); js.onload = function(){ console.log(A) } the load.js file: var A = { name:'aa' } In Chrome, the console outputs "undefined", but the load.js has loaded completely. I tested it in Firefox,