Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #26545 > unrolled thread
| Started by | Luuk <luuk@invalid.lan> |
|---|---|
| First post | 2015-01-11 16:33 +0100 |
| Last post | 2015-01-12 02:01 +0700 |
| Articles | 6 — 3 participants |
Back to article view | Back to comp.lang.javascript
dynamic function Luuk <luuk@invalid.lan> - 2015-01-11 16:33 +0100
Re: dynamic function Martin Honnen <mahotrash@yahoo.de> - 2015-01-11 17:41 +0100
Re: dynamic function Luuk <luuk@invalid.lan> - 2015-01-11 21:20 +0100
Re: dynamic function Martin Honnen <mahotrash@yahoo.de> - 2015-01-12 10:41 +0100
Re: dynamic function Luuk <luuk@invalid.lan> - 2015-01-12 20:44 +0100
Re: dynamic function JJ <jj4public@vfemail.net> - 2015-01-12 02:01 +0700
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2015-01-11 16:33 +0100 |
| Subject | dynamic function |
| Message-ID | <54b297d6$0$2961$e4fe514c@news.xs4all.nl> |
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.
What i want is to be able to execute the call the function 'testje',
which is defined inside the 'testje.js'
This will lead to an htmlpage which will be opened locally on a computer
(not via a web server)
Can anyone give a hint on how to get this done?
[toc] | [next] | [standalone]
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Date | 2015-01-11 17:41 +0100 |
| Message-ID | <m8u93u$2f22$1@adenine.netfront.net> |
| In reply to | #26545 |
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?
> 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>
?
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.
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.
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
[toc] | [prev] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2015-01-11 21:20 +0100 |
| Message-ID | <54b2daf3$0$2854$e4fe514c@news.xs4all.nl> |
| In reply to | #26547 |
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 ---
[toc] | [prev] | [next] | [standalone]
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Date | 2015-01-12 10:41 +0100 |
| Message-ID | <m904t0$13bt$1@adenine.netfront.net> |
| In reply to | #26551 |
Luuk wrote:
> On 11-1-2015 17:41, Martin Honnen wrote:
>> Luuk wrote:
>>> IE complains about 'testje' is undefined.
>>
>> Which version of IE?
>
> IE 11 (Windows 7)
What happens when you implement your include function in the external
file as
function include(scriptSrc) {
document.write('<script src="' + scriptSrc + '"></script>');
}
? Do you still get the error?
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
[toc] | [prev] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2015-01-12 20:44 +0100 |
| Message-ID | <54b42401$0$2888$e4fe514c@news.xs4all.nl> |
| In reply to | #26553 |
On 12-1-2015 10:41, Martin Honnen wrote:
> Luuk wrote:
>> On 11-1-2015 17:41, Martin Honnen wrote:
>>> Luuk wrote:
>
>>>> IE complains about 'testje' is undefined.
>>>
>>> Which version of IE?
>>
>> IE 11 (Windows 7)
>
> What happens when you implement your include function in the external
> file as
>
> function include(scriptSrc) {
> document.write('<script src="' + scriptSrc + '"></script>');
> }
>
> ? Do you still get the error?
>
that 'does not work' too.
Sorry for this answer.
But i see i have to do another approach to my problem.
I have a static piece of html,
with some javascript (http://visjs.org/timeline_examples.html)
My data is (or will be) dynamic.
I'm trying to load a page with this dynamic data, *without* using a web
server. (different users should have different data)
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2015-01-12 02:01 +0700 |
| Message-ID | <1hclnz4jtmgkg$.151xxc3yhb6nv.dlg@40tude.net> |
| In reply to | #26545 |
On Sun, 11 Jan 2015 16:33:43 +0100, 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.
>
> What i want is to be able to execute the call the function 'testje',
> which is defined inside the 'testje.js'
>
> This will lead to an htmlpage which will be opened locally on a computer
> (not via a web server)
>
> Can anyone give a hint on how to get this done?
Do both JS have actually been loaded by IE?
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web