Browser Detection and load

Hi there

I’m not much of a developer I know a bit of everything, html, css, php, mysql not much js though. Well I managed to find a
js menu for a site I’m developing works well. However the position of the menu differs in IE and Firefox. So I’ve made
two seperate .js files and tried to create a script to detect what browser the user is using and then load the
appropriate .js file sounds simple I’m sure it is, but I just can’t get it to work.

Here is my code

<script type=“text/javascript”>
var browserName=navigator.appName;
alert (browserName)
if (browserName==“Netscape”)
function Go(){return}</script>
<script type=“text/javascript” src=“cat.js”></script>
<script type=“text/javascript” src=“menu9_com.js”>
else (browserName==“Microsoft Internet Explorer”)
function Go(){return}</script>
<script type=“text/javascript” src=“cat-ie.js”></script>
<script type=“text/javascript” src=“menu9_com.js”>

What am I doing wrong ?
Thanks in advance for your help


Script tags close a script-
You can’t start a function in one script and continue with it after the script’s end tag.

Hi dantheman187, welcome to the forums

You may have seen PHP code that goes “in and out” of HTML, but PHP is a server-side language and the resulting mark-up doesn’t get output until the code has been interpreted.

Javascript being client-side is different and can be interspersed in the mark-up, but only in complete “blocks” of code, You can set a variable’s value inside one and access it another, but As mrhoo said, you can’t split functions between script tags.

Also I suggest you try to avoid relying on “browser detection” as it’s highly unreliable. IMHO much better to do “compatability detection”.