Click to See Complete Forum and Search --> : How to include a js file inside a js file?


turefugio
12-03-2003, 11:41 AM
I have a table that contains a few js files and is show in all my pages (but the index). To save bandwidth I have decided to convert the this block of information to a js file, but I need to include a few js files, like banner rotations, add to favorites and announcements to this js file and I don't know how to make it work.

I have tried the following without success:
document.writeln('<script language="javascript1.2" src="0favorite.js" type="text/javascript"></script>');

document.writeln('<script language="javascript1.2" src="0favorite.js" type="text/javascript"><\/script>');

document.writeln('<script language=\"javascript1.2\" src=\"0favorite.js\" type=\"text/javascript\"><\/script>');

document.writeln('<script language="javascript1.2" src="0favorite.js" type="text/javascript">');

This is the complete 0table.js, which contains the table that is show in all my pages (the 0favorite.js is in the last line):

document.writeln(" <table bordercolorlight=\"#C1B76C\" border=\"0\" bordercolordark=\"#A89850\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"center\" valign=\"bottom\" height=\"45\"><p align=\"center\"><img height=\"24\" width=\"90%\" src=\"barflores.gif\" border=\"0\"></td></tr><tr><td><div align=\"center\"> ");
document.writeln(" <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td> ");
document.writeln(" <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"messagetop\"><tr><td bgcolor=\"#000000\" valign=\"middle\" align=\"center\"><font color=\"#FFFFFF\"><b><i>");
document.writeln(" </i></b></font></td></tr></table></td></tr><tr><td><div align=\"center\"> ");
document.writeln(" <table border=\"0\" cellpadding=\"0\" cellspacing=\"3\"><tr><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"><a href=\"1hazmehogar.html\" class=\"menu\">HAZME*HOGAR</a></td><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"></td><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"> ");
document.writeln(" <script language="javascript1.2" src="0favorite.js" type="text/javascript"></td><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"><a href=\"1mapa.html\" class=\"menu\">ÍNDICE*MAPA</a></td><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"><a href=\"#envia\" class=\"menu\">ENVÍA*PAGINA</a></td></table></div></td></tr></table></div></td><center></center></tr></table> ");


How can I make it work???
Everyting works but including the 0favorite.js inside the 0table.js file
In advance thanks a lot for your help

turefugio
12-03-2003, 11:48 AM
I have also tried:
document.writeln('<SCRIPT SRC="0favorite.js"></SCRIPT>');

document.writeln('<SCRIPT SRC="0favorite.js"><\/SCRIPT>');

document.writeln('<SCRIPT SRC=\"0favorite.js\"><\/SCRIPT>');

document.writeln('<SCRIPT SRC="0favorite.js">');


document.writeln('<script language="Javascript" type="text\/javascript" src="0favorite.js"><\/script>');

document.writeln('<script language=\"Javascript\" type=\"text\/javascript\" src=\"0favorite.js\"><\/script>');

document.writeln('<script language=\"Javascript\" type=\"text\/javascript\" src=\"0favorite.js\">');

And other similar alterations!

TheBearMay
12-03-2003, 12:00 PM
Well .... in your first post the problem is the quotes inside of quotes. Fixing that yields:

document.writeln(" <table bordercolorlight=\"#C1B76C\" border=\"0\" bordercolordark=\"#A89850\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"center\" valign=\"bottom\" height=\"45\"><p align=\"center\"><img height=\"24\" width=\"90%\" src=\"barflores.gif\" border=\"0\"></td></tr><tr><td><div align=\"center\"> ");
document.writeln(" <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td> ");
document.writeln(" <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"messagetop\"><tr><td bgcolor=\"#000000\" valign=\"middle\" align=\"center\"><font color=\"#FFFFFF\"><b><i>");
document.writeln(" </i></b></font></td></tr></table></td></tr><tr><td><div align=\"center\"> ");
document.writeln(" <table border=\"0\" cellpadding=\"0\" cellspacing=\"3\"><tr><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"><a href=\"1hazmehogar.html\" class=\"menu\">HAZME*HOGAR</a></td><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"></td><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"> ");
document.writeln(" <script language=\"javascript1.2\" src=\"0favorite.js\" type=\"text/javascript\"></td><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"><a href=\"1mapa.html\" class=\"menu\">ÍNDICE*MAPA</a></td><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"><a href=\"#envia\" class=\"menu\">ENVÍA*PAGINA</a></td></table></div></td></tr></table></div></td><center></center></tr></table> ");

MichaelM
12-03-2003, 12:11 PM
javascript won't parse the <script> tag, it will only treat it as a string of text to be written from within the writeln method.

One work around I can see would be to modify 0favorite.js so that instead of it calling writeln with its contents (I'm assuming that 0favorite.js is similar in format to 0table.js), you would instead populate a variable with its contents.

html page would then contain

<script>
var strFavorites;
</script>
<script src=0favorite.js></script>
<script src=0table.js></script>

0favorite.js would have:
strFavorites = "[your current string being passed to document.writeln]";

0table.js would then have:
document.writeln( strFavorites + "</td><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"><a href=\"1mapa.html\" class=\"menu\">ÍNDICE*MAPA</a></td><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"><a href=\"#envia\" class=\"menu\">ENVÍA*PAGINA</a></td></table></div></td></tr></table></div></td><center></center></tr></table> ");

TheBearMay
12-03-2003, 12:36 PM
Hadn't gotten that far into it MichaelM, but you're right.

turefugio
12-04-2003, 07:54 AM
Thanks TheBearMay and MichaelM for you time an interest.

I tried TheBearMay suggestion and it didnot work any better that the ones I have already tried.

Then I tried MichaelM suggestion and with that I am able to see the button but with a message of "undefined" and Front page gives the following message "Unterminated String constant"

The page that calls the js files looks like this:
<script>
var strFavorites;
</script>
<script src=0favorite.js></script>
<script src=0table.js></script>

0favorite.js contains the following:
strFavorites = "[//This code is for IE v4 or better
if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion >= "4.0")
{document.write("<SPAN STYLE='cursor:hand;' onClick='window.external.AddFavorite(location.href, document.title);'>HAZME FAVORITO</SPAN>")}
//This code posts text if not
else
{document.write("Click CTRL-D to add to favorities!")}]";

and 0table.js contains the following:
document.writeln(" <table border=\"0\" cellpadding=\"0\" cellspacing=\"3\"><tr><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"><a href=\"1hazmehogar.html\" class=\"menu\">HAZME*HOGAR</a></td><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"></td><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"> ");
document.writeln( strFavorites + "</td><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"><a href=\"1mapa.html\" class=\"menu\">ÍNDICE*MAPA</a></td><td class=\"button\" onmouseover=\"this.className='cell_over';\" onmouseout=\"this.className='button';\" align=\"center\"><a href=\"#envia\" class=\"menu\">ENVÍA*PAGINA</a></td></tr></table>");

Plese give me other suggestions!

turefugio
12-04-2003, 12:22 PM
Instead of using document.writeln, I used document.write and added the script into the 0table.js. But now I have the following problem with the table (I cannot make recognize the 'cell_over" or the 'button' comand):

How can I use ' (single quotation mark) inside this expression :
document.write('<td class="button" onmouseover="this.className='cell_over';" onmouseout="this.className='button';" align="center"><a href="1hazmehogar.html" class="menu">HAZME*HOGAR</a></td>');

I have tried using:
onmouseover="this.className=\'cell_over\'
onmouseover="this.className="Cell_over"
onmouseover="this.className=+'cell_over+'