Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:33
Simplifying script include line
Poster: etornick
Dated: Monday April 12 2004 - 23:08:36 BST
Currently, it is required to paste the following lines in the file:
<SCRIPT language=JavaScript src="milonic_src.js" type=text/javascript></SCRIPT>
<script language=JavaScript>
if(ns4)_d.write("<scr"+"ipt language=JavaScript src=mmenuns4.js><\/scr"+"ipt>");
else _d.write("<scr"+"ipt language=JavaScript src=mmenudom.js><\/scr"+"ipt>");
</script>
Does anyone know how this could be reduced to a single line like <SCRIPT language=JavaScript src="file_that_has_it all.js" type=text/javascript></SCRIPT>
My client is interested in purchasing the worldwide license but only if this can be done. This is because they are going to require their clients to insert that line in their html files and they don't want the client to paste the 3 lines.
Thanks,
Ed
Poster: etornick
Dated: Tuesday April 13 2004 - 3:49:33 BST
This is one solution... But are there namespace clashes between the two menu libraries? I am also loading an extra library when I don't need it.
I put these 3 lines in one file called somename.js .
somename.js
document.write("<script language='JavaScript' src='milonic_src.js' type='text/javascript'></script>");
document.write("<script language=JavaScript src=mmenuns4.js></script>");
document.write("<script language=JavaScript src=mmenudom.js></script>");
Then I include this one file with a line like
<SCRIPT language=JavaScript src="somename.js" type=text/javascript></SCRIPT>
Any thoughts would be appreciated.
Poster: etornick
Dated: Tuesday April 13 2004 - 3:52:38 BST
On furthur testing it looks like you cant have both libraries included at once. It definitely gets messed up.
Poster: Maz
Dated: Tuesday April 13 2004 - 5:02:49 BST
We probably need more info on what kind of system this is, if its one main system then yes you would normally only include the 3 source files once and link back to them. Then change the menu_data.js accordingly for each.
Maybe you need to integrate it with the backend.
maz
Poster: etornick
Dated: Tuesday April 13 2004 - 14:58:47 BST
All I basically need to do is have the include be for a single file and not the 3 lines of script.
If I just put the lines
<SCRIPT language=JavaScript src="milonic_src.js" type=text/javascript></SCRIPT>
<script language=JavaScript>
if(ns4)_d.write("<scr"+"ipt language=JavaScript src=mmenuns4.js><\/scr"+"ipt>");
else _d.write("<scr"+"ipt language=JavaScript src=mmenudom.js><\/scr"+"ipt>");
</script>
into a file and include that file in the head or body I get a script error. It must have something to do with how javascript is loaded and executed.
I tried putting these lines in a file:
document.write("<script language='JavaScript' src='milonic_src.js' type='text/javascript'></script>");
document.write("<script language='JavaScript'>");
document.write("if (ns4) _d.write('<script language=JavaScript src=mmenuns4.js>') </\script> ");
document.write("else _d.write('<script language=JavaScript src=mmenudom.js>') </\script> ");
document.write("</script>");
and then including the file in a single statement.
It almost works.... the "else_d.write( is not being interpreted correctly.
I am certain that someone who knew javascript well would know what I am doing wrong here.
Any javascript gurus out there?
Any help would be appreciated.
Ed
Poster: John
Dated: Tuesday April 13 2004 - 15:04:44 BST
You could use includes. Put the standard JS calls in one file...
Code:
<script language="JavaScript" src="milonic_src.js" type="text/javascript"></script>
<script language="JavaScript">
if(ns4)_d.write("<scr"+"ipt language=JavaScript src=mmenuns4.js><\/scr"+"ipt>");
else _d.write("<scr"+"ipt language=JavaScript src=mmenudom.js><\/scr"+"ipt>");
</script>
<script language="JavaScript">
if(ns4)_d.write("<scr"+"ipt language=JavaScript src=mmenuns4.js><\/scr"+"ipt>");
else _d.write("<scr"+"ipt language=JavaScript src=mmenudom.js><\/scr"+"ipt>");
</script>
Name this file anything you like - perhaps menu_include.html. I placed mine in the same directory as the menu files - /menu/.
Now, wherever needed, a single include statement will pull all the JS calls...
Code:
<!--#include file="/menu/menu_include.html" -->
The server-relative addressing lets this include be used as is from any directory level.
Note that the exact format of the include statement may need to be adjusted for different server platforms.
Poster: etornick
Dated: Tuesday April 13 2004 - 15:37:49 BST
Hi:
Thanks for your info... but I don't think that will work for me.
What you showed me was a server side include..
My setup is this....
I have a client who provides a service to many clients. Each one of those clients has their own already built web sites.
What these clients will be doing is inserting into their pages a href to my server with a line like....
<SCRIPT src="http://myserver.com/ServletName/somecode"></SCRIPT>
I will be returning to them a specialized menu that will show up in their page when their user mouses over the link in that code I downloaded to their page.
So now I have to require them to paste the 3 lines at the top of their file as well as the include .
One possibility is to have another servlet return the 3 lines...., and a servlet return the menu.... Maybe that is what i should do..
Poster: etornick
Dated: Tuesday April 13 2004 - 16:18:24 BST
The servlet returning the lines made no difference. I think this is a general javascript issue.
The problem seems to be...
<script language="JavaScript" src="milonic_src.js" type="text/javascript"></script>
<script language="JavaScript">
if(ns4)_d.write("<scr"+"ipt language=JavaScript src=mmenuns4.js><\/scr"+"ipt>");
else _d.write("<scr"+"ipt language=JavaScript src=mmenudom.js><\/scr"+"ipt>");
</script>
if (ns4) assumes that the first script src milonic_src.js is already loaded. What I want to have is the first line executed and expanded, then the next lines execute.
If I put all of these lines in a file and have that file included on the client when the client page loads the value ns4 is unknown... also _d which probably is "document" isn't defined yet.
Poster: Maz
Dated: Tuesday April 13 2004 - 17:01:46 BST
Sorry about the delay, I'm sure someone will be along shortly, everyone is in different time zones.
Maybe a minor point, but unable to see what is happening, have you defined all the paths correctly? I assume you are using a full url, if not make sure it has a slash / from root on all 3 src paths.
maz
Poster: etornick
Dated: Tuesday April 13 2004 - 17:06:20 BST
Yes, I am sure that I have the right URL because if I paste the code in directly it will work.
There is only a problem in putting the lines in a file and "including" that file.
Poster: etornick
Dated: Tuesday April 13 2004 - 18:03:24 BST
Just to summarize: I have tried putting these lines in a file called myfile.js:
document.write('<script language="JavaScript" src="milonic_src.js" type="text/javascript"></script> '
+ '<script language="JavaScript"> '
+ 'if(ns4)_d.write("<scr"+"ipt language=JavaScript src=mmenuns4.js><\/scr"+"ipt>"); '
+ 'else _d.write("<scr"+"ipt language=JavaScript src=mmenudom.js><\/scr"+"ipt>"); '
+ '</script>');
And in the html file where the menu will be I have this line:
<SCRIPT language=JavaScript src="myfile.js"
type=text/javascript></SCRIPT>
This results in an error that ns4 is undefined..
I also tried putting this in the file:
document.write("<script language='JavaScript' src='milonic_src.js' type='text/javascript'> </script>");
document.write("<script language='JavaScript' src='mmenudom.js'> </script>");
This works because the test for ns4 is not there and I am just loading the mmenudom.
Poster: Andy
Dated: Tuesday April 13 2004 - 18:36:36 BST
Hi,
Adding, this code:
Code:
if(ns4)_d.write("<scr"+"ipt language=JavaScript src=mmenuns4.js><\/scr"+"ipt>");
else _d.write("<scr"+"ipt language=JavaScript src=mmenudom.js><\/scr"+"ipt>");
_d.write("<scr"+"ipt language=JavaScript src=menu_data.js><\/scr"+"ipt>");
else _d.write("<scr"+"ipt language=JavaScript src=mmenudom.js><\/scr"+"ipt>");
_d.write("<scr"+"ipt language=JavaScript src=menu_data.js><\/scr"+"ipt>");
At the end of milonic_src.js will work
Cheers
Andy