Thursday, May 22, 2008

JavaScript - Browser & Version Redirect

If you maintain separate pages for Netscape and Internet Explorer browsers and want to additionally divide each browser's page into version pages, this script is for you. The script will create a link (or can be changed to automatically redirect) to browser[version number].html. (For example, a visitor with Netscape 4.5 would see a link to netscape4.html) Here there would be a link for msie4.html







<!-- ONE STEP TO INSTALL BROWSER & VERSION REDIRECT:

1. Add the last code into the BODY of your HTML document -->


<!-- STEP ONE: Copy this code into the BODY of your HTML document -->


<BODY>


<SCRIPT LANGUAGE="JavaScript">


<!-- Begin


var name = navigator.appName;

var vers = navigator.appVersion;

vers = vers.substring(0,1); // or 0,4 could return 4.5 instead of just 4


if (name == "Microsoft Internet Explorer")

url="msie";

else

url="netscape";

url += vers + ".html";

document.write('<center>');

document.write('<A HREF="' + url + '">Enter</A>');

document.write('</center>');


// You may make the redirection automatic by using this

// window.location=url;

// instead of the three document.write lines above


// End -->

</script>




No comments: