/    Sign up×
Community /Pin to ProfileBookmark

.js External File

I am having a terrible time getting an external .js file to work. I have the following code:

<!– Keep all menus within masterdiv–>
<div id=”masterdiv”>

<div class=”menutitle” onclick=”SwitchMenu(‘sub1’)”>Site Menu</div>
<span class=”submenu” id=”sub1″>
– <a href=”new.htm”>What’s New</a><br>
– <a href=”hot.htm”>What’s hot</a><br>
– <a href=”revised.htm”>Revised Scripts</a><br>
– <a href=”morezone/”>More Zone</a>
</span>

</div>

I want to copy this into a menu.js file and not have to include the code on
every page. I have expanded the menu into several subsets so code is much
longer than above. Do I just copy the code above as is into a menu.js file or do I need to do something else with it???

Once that is done, how do I reference the menu.js file on each page of the
web site to get the menu to appear? I’ve tried all kinds of combinations from
web site help pages and a couple of books I have and can’t seem to find the
right combo. There is another section of code that goes in the HEAD section
but that is included in my page template and on every page which is not a
problem. I just want the above in a separate menu.js file so when I have to
change something in the menu I do not have to do it 30 times.

Thanks in advance.
K

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@nap0leonDec 28.2007 — Unless you create a function that writes the menu onto each page, you won't place the menu in the JS file. Rather, place the menu in "menu.html" that you could reference on each page as
[CODE]
<!-- #include file="menu.html" -->
[/CODE]


The function "SwitchMenu(item)" would go into your JS file and can be referenced in the head section as
[CODE]
<SCRIPT LANGUAGE="JavaScript" SRC="JScript.js"></SCRIPT>
[/CODE]
×

Success!

Help @kpervine spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...