Announcement

Do not use the forums to submit bug reports, feature requests or patches, submit a New Ticket instead.

#1 2007-02-28 22:08:26

chasin
New member
Registered: 2005-06-12
Posts: 5

using <script src=""> in edit area

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

#2 2007-03-01 03:26:19

jedi58
Xinha Authority
From: Leicester, UK
Registered: 2007-01-14
Posts: 113
Website

Re: using <script src=""> in edit area

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

#3 2007-03-01 10:47:33

chasin
New member
Registered: 2005-06-12
Posts: 5

Re: using <script src=""> in edit area

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

#4 2007-03-01 14:15:31

jedi58
Xinha Authority
From: Leicester, UK
Registered: 2007-01-14
Posts: 113
Website

Re: using <script src=""> in edit area

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

#5 2007-03-01 16:31:41

chasin
New member
Registered: 2005-06-12
Posts: 5

Re: using <script src=""> in edit area

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

#6 2007-03-02 14:56:25

ray
Xinha Administrator
From: Germany
Registered: 2005-03-23
Posts: 521
Website

Re: using <script src=""> in edit area

The editor area is an iframe, thus a different window, thus js in the main window is not available inside

Offline

#7 2007-03-13 16:23:23

chasin
New member
Registered: 2005-06-12
Posts: 5

Re: using <script src=""> in edit area

ray wrote:

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

Board footer

Powered by FluxBB