Javascript in the head

Hello folks. I am a new user of Sparkle, which I bought to re-develop my website. I build musical instruments and write books about them so this is my advertising. The page on the website which attracted the most hits (by a factor of ten!) calculate strings tensions of guitars and similar instruments. It is a chunk of javascript that was written some years ago and sits in the head section of the page. I have tried embedding the javascript text but nothing happens. Is it possible to use this script in Sparkle? It would be annoying if I can’t as everything else about this software is a joy and is making redoing the website rather fun. The page is very utilitarian looking but it does work and gets several hundred uses a month.


Graham (in Australia)

I had a quick look and that is one long javascript snippet!

You are right by it not working so there must be more to it like hooking into the HTML? HTML and CSS is my strong point not javascript so I’m sure someone else will come round and help you out better.

Personally, I would save the head code as an external javascript file. Then in sparkle you just add a simple source statement through the code widget. the code you add would be:
<script src="myScript.js"></script>

Change the myScript.js to the name of your actual script file. It doesn’t have to go in the head section specifically - it will work just as well if it’s in the body of the page, which I think is where sparkle will put it.

Obviously, to make it work you will have to ensure that the css directories and files exist in your site structure. You will only be able to add these after publishing your site to a local folder. You would then add the .js file and the css files to the published folder. You will then be able to test locally before uploading to a server. If there are any problems it will most likely be something to do with paths to certain files, either in the javascript itself or in the main body code you add to the page.