Click to See Complete Forum and Search --> : Part of JS in HTML, part in JS file...


Zifnab
07-03-2003, 04:12 AM
I have a very large external JS file. Now, instead of having 2 or more different versions of the entire file for only a dozen lines that are different seemed like a bit of overkill, thus I wondered if it's possible to put the "different part" of the JS in the HTML file, while keeping all the rest in the JS file... or if this isn't possible, if there's any other way to do this?

The JS file is a whole list of functions being declared and near the end the part that I want to leave in the HTML file (or at least put somewhere else besides that JS file). It's something like this (the part I want outside):

var mBar = new ItemStyle(17, 1, '', 0, 0, '#000066', '#FFCC00', 'lowText', 'highText',
'lBorder', 'hBorder', null, null, 'hand', 'default');

var subBorder = new ItemStyle(17, 1, '', 0, 0, '#000066', '#FFCC00', 'lowText', 'highText',
'lBorder', 'hborder', null, null, 'hand', 'default');

var subBlank = new ItemStyle(16, 1, '', 0, 0, '#000066', '#FFCC00', 'lowText', 'highText',
'nBorder', 'oBorder', null, null, 'hand', 'default');


var pMenu = new PopupMenu('pMenu');
with (pMenu)
{
startMenu('root', true, 0, 0, 77, mBar, 'menuBar');
addItem(' FILE', 'mFile', 'sm:');
addItem(' Edit', 'mEdit', 'sm:');
addItem(' Help', 'mHelp', 'sm:');
addItem(' Visit My Site', '#', '');

startMenu(...); //and so on...
//...
//...
}

startMenu, addItem, etc are all declared before that part in the same js file...
And after that the JS that's still in the file is:

if (!isOp && navigator.userAgent.indexOf('rv:0.')==-1)
{
pMenu.showMenu = new Function('mN','menuAnim(this, mN, 10)');
pMenu.hideMenu = new Function('mN','menuAnim(this, mN, -10)');
}

Followed by the "menuAnim" function declaration...

David Harrison
07-03-2003, 04:17 AM
If you want some js in the HTML file do this.

<html>

<head>

<title>Page</title>

<script type="text/javascript" src="file.js"></script>

<script type="text/javascript"><!--

// Stuff.

//--></script>

</head>

...the rest...