You are not logged in.
In html mode, I type in the following:
<script>
function hello() {
alert("hello");
}
</script>
<button onclick="hello()">blah<button>
Now when I switch to Wysiwyg mode,
clicking on the button pops up a window
Then I put the above script in a .js file, and then in html
mode, I change to:
<script src="helloText.js">
<button onclick="hello()">blah<button>
But now when I go to wysiwyg mode, press the button, no
alert window pops up. I get a function not found error.
I know the script is loaded since I added the following to test:
objs = document.getElementsByTagName("script");
for ( i=0;i<objs.length;i++ ) {
alert(objs[i].src);
}
Any ideas if I can load javascript like this?
Offline
the script tag isn't closed - it should be <script src="..." type="text/javascript"></script>
because the script tag isn't closed the browser is ignoring what's after it
Last edited by jedi58 (2007-03-01 03:27:34)
David G. Paul
[url]http://www.newearthonline.co.uk[/url]
Offline
Thanks David, but that was my typo mistake.
Adding the type="text/javascript" does not fix the problem. I get an undefined function error when I go to Wysiwyg mode. Any other ideas much appreciated. I tried adding the .js as a plugin but that didn't work either.
Offline
it's probably down to file location then, make sure the path points to the file relative to where Xinha has been included
David G. Paul
[url]http://www.newearthonline.co.uk[/url]
Offline
Wierd, it's not a file issue, I'm still at trying to figure this out but at this point, I don't think loading a Javascript file then accessing a function in the editor works. I have a hack going to grab the .js file, embed the contents with script tags using AJAX. I'll post if I come up with anything else.
Offline
The editor area is an iframe, thus a different window, thus js in the main window is not available inside
Thanks Ray, but I'm putting the <script src=""> in html mode then switching to wysiwyg and the javascript does not run. For example, if I add inline script i.e. <script ...> alert("text"); </script>in html mode, switch to wysiwyg, then the script runs. But if I put the identical script in a js file, add the <script src="..."> in html mode, then switch to wysiwyg, the js does not run. Hope I'm making sense.
Offline