July 28, 201016 yr Hi So I'm just trying to creat a simple script which finds the browser a visitor is using, replaces the name and then writes the result to the page: Heres the basic script: <head> <script type="text/javascript"> var browser = navigator.appName; var browserName = getName(); function getName() { if ( browser == netscape) { document.write("Firefox"); } else if ( browser == Microsoft Internet Explorer ) { document.write("Internet Explorer"); } else { document.write("a web browser"); } } </script> </head> <body> <p> You are using <script type=(text/javascript)> browserName </script>. </p> </body> Let me know if I have missed somthing you might need to solve this really rather simple script, simple if you arent a complete newbie to javascript!!
July 28, 201016 yr Author Well spotted thanks, but thats not what is causing the problem is it? I though the semi colons were just good practice not required?
July 28, 201016 yr Not tested but try <head> <script type="text/javascript"> var browser = navigator.appName; var browserName = getName(); var display = document.getElementById('browser'); function getName() { if ( browser == 'netscape') { display.innerHTML("You are using Firefox"); } else if ( browser == 'Microsoft Internet Explorer' ) { display.innerHTML("You are using Internet Explorer"); } else { display.innerHTML("You are using a web browser"); } } </script> </head> <body onLoad="getName();"> <p id="browser"> </p> </body>
Create an account or sign in to comment