Forum Moderators: coopster & phranque

Message Too Old, No Replies

Javascript buried in .CSS

Is this possible and if so how ?

         

eboda

5:16 am on Mar 31, 2002 (gmt 0)



Greetings people,

I have a question - I have created a nifty java script, and I would I bury the java script for the <head> section of a site within .css.

Is it possible to put java script within .css and to be placed in a specified area like the <head>? If so would anyone be willing to share an example?

Could not find much info anywhere so that is why I have come here ;)

Thanks much!
eboda

william_dw

5:14 pm on Mar 31, 2002 (gmt 0)

10+ Year Member



Hi there,
You cant put JavaScript directly inside a CSS file because the browser is expecting CSS, similar to you seeing microsoft.com when you visit webmasterworld, it's just not what you expect.

There is a way which should work for you though,
simply put the javascript inside a file, for example myscript.js (the extension dosent really matter, but it's easier to find that way), and then use this code to include that script in your page:

<script language="javascript" src="myscript.js"></script>

Do not use <script> tags inside the myscript.js file, it should look like this:
(start myscript.js)


alert('I dont really do anything, i\'m an example!');
(end myscript.js)

You can place the <script lang...> tag anywhere on the page, if you put it in the <head> then it will be loaded before any content is displayed to the user.

HTH,
Dw

eboda

8:24 pm on Mar 31, 2002 (gmt 0)



Sometimes I feel like an idiot. Perhaps coding all day the simple solution can slip ones brain.

(Ducking away thumping myself on the head ... ugh!) :)

Thanks
eboda