View Full Version : Tab Content Script -> external.js ?

eau femme
04-15-2005, 10:47 PM
DD Script: Tab Content Script (http://www.dynamicdrive.com/dynamicindex17/tabcontent.htm)

I have incorporated the css from this DD script into my sitewide css file and would like to have the script be called as an external js file. I realize there are pros and cons to having scripts called from an external file, but I use this script so frequently it would be nice to have it in one location for easy updating as new features are added. I will keep copywrite notice on the webpage itself -

So, here are my questions:

1. Can this script be placed in an external .js file?
2. If so, how would I do it?

Thanks for your help !

04-15-2005, 11:34 PM
There's no reason why this wouldn't work- simply put the script inside code of Step 1 inside an external .js file, and reference it as such:

<script src="tabcontent.js" type="text/javascript">
* Tab Content script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code

Note that in order to comply with our usage terms, the credit notice must remain intact in the visible source as shown above.

eau femme
04-16-2005, 12:51 AM
I have included the code as an external file as you suggested and it works - thanks :)

I have two additional questions:

1. Is there an easy was to pass information to set the default tab information from the html code? I have different tabs as default on different pages. I believe I can overcome this by loading a version of the external file - e.g. tabcontent5.js to load tab 5. Any other suggestions would be welcome.

2. I have noticed that wierd text is showing up just prior to copywrite notice as well as anywhere within the divs that contain the tab content where there is an apostrophe ' or quotation marks " The type of text ranges from garbage to a simple

I have removed the wierd text, saved the file then reopened only to find the wierd characters re-appearing. Any ideas?

P.S. the wierd text did not occur prior to moving the script from the webpage to the external js file.

04-16-2005, 01:03 AM
Regarding setting the default tab, what you can do is include a small snippet of script just above the HTML for the tabs:

<script type="text/javascript">
//[which tab (1=first tab), ID of tab content to display]:
var initialtab=[1, "sc1"]

This will override the default tab setting in your external .js file.

Regarding 2), do you have an online example of the problem? Also, what browser are you using?

eau femme
04-16-2005, 11:01 AM
Thank you once again, the code snippet did the trick. :) You just taught me something that I did not know - I guess it is kinda like overriding style sheet fonts, sizes etc. Just modify the default variables in a js code where needed. It makes perfect sense. I have looked and there are several other places on my website where this override trick could be useful.

Thanks for adding something else to my toolkit ddadmin :)

With regard to number 2, I do not have an online example yet - the wierd characters were occuring while updating my site pages using an editor. The good news is that the problem seems to have resolved itself. I have no idea why - I shutdown and rebooted and behold, wierd characters did not appear when I loaded the page in the editor.