Forum Moderators: open
I redesign old sites and keep finding special code for Navigator, like the following, and just wondering if it's still necessary?
<script language="JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW ¦¦ innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
</script>
On another site there is an index.cgi page (designed in 2001) that redirects all netscape and IE broswers (even the newest ones) to certain pages.
Is this still necessary also?
It seems to me this would be a javascript redirect which Google has banned. Yes?
Is it still necessary to set up special code for Netscape Navigator?
I hope this doesn't derail your question - but I learned a trick long ago from the NN developer pages themselves which are no longer in existence.
It's a bad idea to take *any* action based on browser identification. This becomes a maintenance nightmare, one which reveals itself over time. Your example is a perfect demonstration.
If you need to do something that may work differently in various browsers and platforms, what you want to do is test for the object or functionality when the page is requested. For example,
if (document.getElementById) {
// do something with id'ed elements
}
So if you still have an old browser or even a text-only browser that does not handle document.getElementById, whatever goes on here will get completely ignored and will use your non-JS alternate. The good part is, until browsers no longer react to getElementById (probably 'never') this will always work regardless of browser or operating system.
That is, so long as whatever you put in the 'if' uses standards and not proprietary methods or references to proprietary objects.