Jump to content

Load External .js File


William C Bruce

Recommended Posts

I have 50 or so books to display sorted by years.Each year has its own external .js with an array and section variablesIs there a way to selectively load the appropriate .js file depending on the year selected?I'd rather not have 50 or so html pages defined by year, each linking to it's own .js file.Obviously I'd rather not have to link to every .js file.I've looked into the doc.write (script file) scenario but did'nt care much for that. I hope there's another solution.Please excuse my first attempt to post a question.

Link to comment
Share on other sites

U could use Javascript to dynamicaly load the JS files. But i need a little more information to help u. Like how are the books being selected what exactly is in JS files. And u said something about not wanting to have 50 links well if they are sorted on year u could use javascript to dynamically generate links like this

for (i = 0; i <= 50; i++) { //code for generating the link with the I as Index}

Link to comment
Share on other sites

If you want to dynamically add a Javascript file to the page, you could follow Google's example and use document.write to put a script tag on the page. You'll have to experiment with how it works though, I believe one script block has to end in order for it to read the new file. e.g.:

<script type="text/javascript">document.write('<script type="text/javascript" src="code.js"></script>');// code here won't be able to access anything from code.js</script><script type="text/javascript">// this code can access the new code</script>

Link to comment
Share on other sites

U could use Javascript to dynamicaly load the JS files. But i need a little more information to help u. Like how are the books being selected what exactly is in JS files. And u said something about not wanting to have 50 links well if they are sorted on year u could use javascript to dynamically generate links like this
for (i = 0; i <= 50; i++) { //code for generating the link with the I as Index}

Thanks for your reply. I'll see id I can give you more adequate info.At humefoggtech.com (or hft1.com for short) , on the "yearbooks" page there are thumbnails from yearbooks dating as far back as 1917. I have been previously been building a dedicated page for each year. the visitor clicks a thumbnail and the link takes them to that page. The page is a slideshow with more bells and whistles than the law allows but it's what the owner(my brother)wants. Since each year has any where from 60 to 260 pages, I've set up an external array file listing the pages and some other year specific variables like directory path, book name, section names and page numbers etc.We now have seven new yearbooks to scan and I was hoping to find a way to have a single "slideshow.html" page and pass the year to the page via the url link (?year=19XX) or something like that. I am currently running one slideshow script from a single .js file on every page. As a matter of fact, all the pages are identical except for the year value in three or four places.I can retreive the year variable from the url pass strategy, and use it everywhere except for the array .js link.Does this info give you enough to go on?Thanks again for the help.
Link to comment
Share on other sites

U could use Javascript to dynamicaly load the JS files. But i need a little more information to help u. Like how are the books being selected what exactly is in JS files. And u said something about not wanting to have 50 links well if they are sorted on year u could use javascript to dynamically generate links like this
for (i = 0; i <= 50; i++) { //code for generating the link with the I as Index}

Thanks for your reply. I'll see if I can give you more adequate info.At humefoggtech.com (or hft1.com for short) , on the "yearbooks" page there are thumbnails from yearbooks dating as far back as 1917. I have been previously been building a dedicated page for each year. the visitor clicks a thumbnail and the link takes them to that page. The page is a slideshow with more bells and whistles than the law allows but it's what the owner(my brother)wants. Since each year has any where from 60 to 260 pages, I've set up an external array file listing the pages and some other year specific variables like directory path, book name, section names and page numbers etc.We now have seven new yearbooks to scan and I was hoping to find a way to have a single "slideshow.html" page and pass the year to the page via the url link (?year=19XX) or something like that. I am currently running one slideshow script from a single .js file on every page. As a matter of fact, all the pages are identical except for the year value in three or four places.I can retreive the year variable from the url pass strategy, and use it everywhere except for the array .js link.Does this info give you enough to go on?Thanks again for the help.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...