PDA

View Full Version : .js files (CSS made me think of this question)



Sliight
07-15-2007, 05:44 PM
I'm brand new to this, so forgive me if this is a daffy question.

I've learned how CSS can apply many things to many pages from one file. I recently noticed a .js javascript file in my directory from a menu tabs I downloaded from here. It told me to put it in the directory so I did.

I was wondering if this .js file can contain everything to do with the script, ie the list it needs, as well as links and labels within the list? This way I could just simply imbed it in a div and place it in every page.

The reason I'm asking this, is that it would allow me to update every link and target on the menu without having to do this page by page.

Any thoughts?

Thanks :)

Twey
07-15-2007, 05:53 PM
It's a bad idea, since the menu links will be unavailable to non-JS users.

Sliight
07-15-2007, 06:14 PM
Ahh that makes sense... well with that in mind, I suppose once I get the nav bar dropping down in the wrong place fixed... I should create pages for each of the top 9 main links that takes them to a menu page so they can access the list of links as well? Or will the whole list show up without JS on?

Thanks :)

Twey
07-15-2007, 07:05 PM
Depends on the script. The former is the accepted solution if they don't, though.

djr33
07-16-2007, 01:46 AM
The better idea here would be to use PHP or another form of server side inclusion. It can do the exact same thing, but will work for all browsers/users.

Sliight
07-16-2007, 06:17 AM
Ack you didn't just say PHP did you? I just spent the week buried in turorials on HTML and CSS and was starting to see the light!!!! :)

Anyone know where a good PHP tutorial is? Oh, and anyone know what PHP is? :D

Thanks,

djr33
07-16-2007, 08:42 AM
PHP is very simple, in its most basic uses. And the include function is one of those. It will be very daunting at first, but just because you're not used to it. There's nothing very complex about its use.

<?php include('file.ext'); ?> Will include (take the contents of) a file, and output that data exactly where that tag is, like <div><?php ... ?></div> would fill the div with the data of a file.

The page MUST end in .php, and your server must have PHP installed/enabled.

And that's it.

It won't change how anything on your page functions.

You will also not see it in the source code as PHP is executed before the page it sent, then outputting plain text, just as if you have cut and paste the contents of the included file yourself.

mwinter
07-16-2007, 05:24 PM
There's nothing very complex about [the] use [of PHP].

That's not strictly true: anyone using PHP or some other server-side language should understand the HTTP protocol properly. Not doing so can adversely affect interactions with the server. These effects can be the relatively minor, such as wasted bandwidth, to the major: rejected communication.

Just because PHP as a language is simple - too simple, in my opinion - doesn't mean that using it is necessarily the same.