0

See the source of http://marakana.com/s/post/1096/samples/try6.htm It defines a function and calls it on load of document. (Which is the final step of this tutorial)

I tried to put it into a seperate JS file. Runs correctly only if I call onload both in JS and in HTML. But not only body onload or only from JS. I guess I am doing something wrong. So, following works:

<head>
<script src="Scripts/makeWYSIWYG.js" type="text/javascript"/>
<script type="text/javascript">
            window.onload = function () {
               makeWYSIWYG(document.getElementById('editor'));
            };
</script>
</head>
<body onload="makeWYSIWYG(document.getElementById('editor'));">

Why do I need to call the function twice?

I only have the function definition in "Scripts/makeWYSIWYG.js" function makeWYSIWYG(editor) { ... return editor; };

Thanks,

Ozgur Ozturk
  • 1,265
  • 11
  • 9

2 Answers2

0

There are no reason to call the function twice. The is enough.

With the first window.onload you could be changing a former function callback assignment (i.e. in a imported script).

0

The problem was actually the closing tag, "/>", here:

<script src="Scripts/makeWYSIWYG.js" type="text/javascript"/>

I should have written:

<script src="Scripts/makeWYSIWYG.js" type="text/javascript"> </script>

I guess the second script was helping the tag to be closed and making it run...

More info here: Why don't self-closing script tags work?

Community
  • 1
  • 1
Ozgur Ozturk
  • 1,265
  • 11
  • 9