Page 1 of 2
Getting javascript to run.
Posted: Fri Oct 31, 2008 3:05 pm
by alumwell
Hello.
I'm trying to run this piece of javascript on a page:
Code: Select all
{literal}
<__script__ type="text/javascript"><!--
//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
//new fadeshow(fadeimages, 140, 225, 0, 3000, 1, "R")
new fadeshow(fadeimages2, 140, 225, 0, 3000, 0)
// --></__script>
{/literal}
Although i cannot get it to run. I have the other needed files in the correct place. Any suggestions why?
Re: Getting javascript to run.
Posted: Fri Oct 31, 2008 4:18 pm
by Dee
The script will be run this way (surrounded with {literal}{/literal} tags). It creates a new fadeshow object, it's hard to tell why it doesn't work without the source of the js file containing the class definition and without knowing how you've included that.
Regards,
D
Re: Getting javascript to run.
Posted: Mon Nov 03, 2008 8:31 am
by alumwell
Re: Getting javascript to run.
Posted: Mon Nov 03, 2008 8:47 am
by hexdj
Well, did you add the code from Step 1 on that link that you posted?
Re: Getting javascript to run.
Posted: Mon Nov 03, 2008 9:02 am
by alumwell
yep. I put it in a .js file and put it in the main template in the head like:
Code: Select all
{literal}
<__script__ type="text/javascript" src="lib/slideshow.js" ></__script>
{/literal}
And when i view source it says:
Code: Select all
<head>
<__script__ type="text/javascript" src="lib/slideshow.js" ></__script>
<title>A....etc
Any suggestions?
Thanks
Re: Getting javascript to run.
Posted: Mon Nov 03, 2008 9:10 am
by alumwell
Also it seems to automatically seems to put '<!--' into the code when i apply, am i correct in saying this comments it out? If so could that be why it's not working?
Thanks.
Re: Getting javascript to run.
Posted: Mon Nov 03, 2008 3:02 pm
by NaN
Is your js file really located in the lib folder of cmsms?
Are there sufficient permissions to directly access js files?
Where are the comment tags placed in the source?
What seems to be commented out?
Re: Getting javascript to run.
Posted: Tue Nov 04, 2008 12:23 am
by kittymcooper
I had the same problem when adding some javascript to a page and had to remove the comments normally put in after and before to hide it from old browsers because the html editor loses the line breaks. Perhaps there is a better solution but removing the comments works.
So
becomes
some javascript code
and now it works
Re: Getting javascript to run.
Posted: Tue Nov 04, 2008 8:50 am
by alumwell
Hello.
1. Yes, the js is in the lib folder.
2. i don't believe there is any permissions problem
3. It automatically seems to put the comment in:
Code: Select all
{literal}
<__script__ type="text/javascript">
//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
//new fadeshow(fadeimages, 140, 225, 0, 3000, 1, "R")
new fadeshow(fadeimages2, 140, 225, 0, 3000, 0)
</__script>
{/literal}
Turns to this when you update:
Code: Select all
literal}
<__script__ type="text/javascript"><!--
//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
//new fadeshow(fadeimages, 140, 225, 0, 3000, 1, "R")
new fadeshow(fadeimages2, 140, 225, 0, 3000, 0)
// --></__script>
{/literal}
Re: Getting javascript to run.
Posted: Tue Nov 04, 2008 1:35 pm
by duclet
Try adding a semicolon at the end.
Re: Getting javascript to run.
Posted: Tue Nov 04, 2008 3:40 pm
by alumwell
just tried. Still puts the around the javascript.
Any other ideas?
thanks.
Re: Getting javascript to run.
Posted: Tue Nov 04, 2008 5:30 pm
by NaN
The comment tags are just to avoid that the script will be displayed as text in old browsers that cannot handle javascript.
It has nothing to do with the functionality of the script.
But why are these two lines commented out?
//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
//new fadeshow(fadeimages, 140, 225, 0, 3000, 1, "R")
Re: Getting javascript to run.
Posted: Wed Nov 05, 2008 10:28 am
by alumwell
NaN wrote:
The comment tags are just to avoid that the script will be displayed as text in old browsers that cannot handle javascript.
It has nothing to do with the functionality of the script.
But why are these two lines commented out?
//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
//new fadeshow(fadeimages, 140, 225, 0, 3000, 1, "R")
They are not needed. I've already removed those to lines to try and get it to work. Any other ideas?
Thanks.
Re: Getting javascript to run.
Posted: Wed Nov 05, 2008 6:35 pm
by hexdj
Are you sure JS is turned on?
Re: Getting javascript to run.
Posted: Wed Nov 05, 2008 10:06 pm
by kittymcooper
The comment tags will disappear the js code in all browsers, if they do not have line breaks after them (\n) -
I was able to remove the comments by using the html editor from the icon in the wsyiwyg editor that comes with CMSMS which did not add the comments and did solve this issue for me.