permaculture playing cards
The moose likes HTML, CSS and JavaScript and the fly likes Including .js files into certain pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Including .js files into certain pages" Watch "Including .js files into certain pages" New topic

Including .js files into certain pages

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Could anyone suggest how I can put together some Javascript to check which page I am on and load the approriate js file into the header?

I am using an include file for my header but do not want all of my JS files loaded into the header, so thought I could write some loginc to only load the appropriate JS file(s) for that page.

I have the basic:-

To find my url, but what I want is something like:-

Cheers in advance
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63355

Personally, I just hand-tune what each page needs rather than use some complicated and possibly fragile mechanism. But, you might want to check out jQuery's $.getScript() function.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

You might also look into the decorator pattern and/or just use an existing solution like SiteMesh.

GenRocket - Experts at Building Test Data
subject: Including .js files into certain pages
It's not a secret anymore!