Subscribe

Saturday 27 February 2010

WordPress And Javascript

This is going to be a short post and a bit off-topic yet I found it a quite interesting.
I have another blog using WordPress and I wanted to incorporate a page from my earlier web-site which gave user's the opportunity to listen to music online. The page is quite simple, it has a bunch of radio buttons with different radio station links and all you got to do is click on one of them and the javascript will take care of the rest.
Nifty isn't it, therefore I created a wordpress page and copied my HTML.Javascript onto that page. Easy..... unfortunately when I previewed the page it did not work, the page and the options showed all right yet the javascript refused to work. When I went back to check the code of my page, lo behold there were

tags all round my javascript lines and no way out.
A little research later realized that I have to put the javascript in a separate file and then link it with the page
Here is the example (assume my script is called radioScript.js)
<script type="text/javascript" src="/radioScript.js"></script>
That's it and now you can call any function written in the file. I have created the page and is online if you care to have a look at it please click here or go to http://best-news-site.com/radio-2
Very soon I will post again showing you how to create a simple widget for WordPress
See you, don't forget to subscribe to my feed for the latest updates

No comments:

Post a Comment

 
EatonWeb Blog Directory