Luuk
1/11/2015 8:20:00 PM
On 11-1-2015 17:41, Martin Honnen wrote:
> Luuk wrote:
>>
>>
>> I have jsHandler.js (found on the internet) with this:
>> function include(filename)
>> {
>> var head = document.getElementsByTagName('head')[0];
>>
>> script = document.createElement('script');
>> script.src = filename;
>> script.type = 'text/javascript';
>>
>> head.appendChild(script)
>> }
>>
>> I have a file called testje.js with this:
>> function testje() {
>> document.write('testje');
>> }
>>
>>
>> My html looks like this:
>> <!DOCTYPE html>
>> <html>
>> <head>
>> <title>testje</title>
>>
>> <script src="jsHandler.js"></script>
>> <script>
>> include('testje.js');
>> </script>
>> <body onload='testje();'>
>> </body>
>> </html>
>>
>>
>> IE complains about 'testje' is undefined.
>
> Which version of IE?
IE 11 (Windows 7)
>
>> What i want is to be able to execute the call the function 'testje',
>> which is defined inside the 'testje.js'
>
> Why can't you use
>
> <script src="testje.js"></script>
>
> ?
Because in the end i first want to determine the name of the 'extra'
javascript to be loaded, and after that i want to load the appropriate
script.
>
> And why do you use "createElement" and "appendChild" in one function to
> create elements to then try to call a function "onload" that does a
> "document.write", which would overwrite the existing document? That all
> does not make sense to me.
>
sorry, my example was bad .... ;-)
> If you want to call a function loaded by a dynamically created and
> inserted "script" element you might be better off to set up a "load"
> event listener on that "script" element and call any function in the
> event listener.
my javascript knowledge is letting /me down on this one.
but i hope i know what you mean by that tomorrow ;-)
>
>
>
>
>
>
> --- news://freenews.netfront.net/ - complaints: news@netfront.net ---