/    Sign up×
Community /Pin to ProfileBookmark

Browser redirection

I am trying to implement a new navigation menu on a web site.
Because NS4 renders fonts 1pt smaller than IE, I am using some browser detection to call the appropriate menu.js file.

Here’s the relevent code so far (no lines wrap despite what you may see here):

<script language=”JavaScript1.2″>
<!–

var browser_type = navigator.appName;
var browser_version = parseInt(navigator.appVersion);

//if NS 6+
if (browser_type == “Netscape” && browser_version >= 5) {
document.write(“<script type=’text/javascript’ language=’JavaScript1.2′ src=’menu.js’></script>”);
}
//if IE 4+
else if (browser_type == “Microsoft Internet Explorer” && browser_version >= 4) {
document.write(“<script type=’text/javascript’ language=’JavaScript1.2′ src=’menu-ie.js’></script>”);
}
//if NS 4+
else if (browser_type == “Netscape” && browser_version == 4) {
document.write(“<script type=’text/javascript’ language=’JavaScript1.2′ src=’menu-nn.js’></script>”);
}
// –>
</script>

IE seems happy with this, but NS is choking.
NS7 will display the entire page EXCEPT for the menu.
NS4 just chokes and has to be killed off.

I’ve discovered some interesting things:

  • 1.

    If I modify the document.write from
    src=’menu.js’>
    to
    src=’menu.js’&gt;
    I will get the menu on NS7 and IE, but everything in the body is missing until I hit a later </script> tag further down in my page. NS4 displays nothing from the menu down.

  • 2.

    If I now add an additional </script> at the bottom of the nav script so that it now looks like
    // –>
    </script>
    </script>
    NS7 and IE displays everything, but NS4 will only display the page body without a menu. Apparently, the script is not being terminated properly.

  • I’ve tried so many things, like additional escapes (), translating angle brakets to &lt; and &gt; , splitting lines, you name it. Something is very wrong here. Can someone help me out?

    The entire page can be found at [url]http://www.symark.com/testnav.htm[/url]

    Thanks in advance.

    to post a comment
    JavaScript

    11 Comments(s)

    Copy linkTweet thisAlerts:
    @silverbobauthorNov 23.2002 — Thanks, Dave. But, I get the same results.

    IE is happy

    NS6 displays the page, but no menu

    NS4 hangs during page load

    If I change

    str += '"></script>';

    to

    str += '"&gt;</script>';

    IE and NS7 display the menu, but nothing else on the page until after a </script> tag near the bottom of the page. NS4 displays the header above the menu and nothing else.

    Interesting, huh?

    If only there weren't browser differences, this would be so easy!
    Copy linkTweet thisAlerts:
    @silverbobauthorNov 23.2002 — Dave -

    There's no XML or anything going on. Check out the page yourself,

    http://www.symark.com/testnav.htm

    I too have tried escaping everything and everywhere. Regarding these suggestions:

    str += '"></script>';

    IE works fine

    NS4 chokes during page load and hangs

    NS7 displays the entire page EXCEPT for the menu.

    or this:

    str += '"/></script/>';

    IE still happy

    NS4 displays only the page header above the menu and nothing else.

    NS7 displays the page header and menu and nothing else until after another <script></script> at the bottom of page.

    ?
    Copy linkTweet thisAlerts:
    @gil_davisNov 23.2002 — May I butt in?

    If you View|Page Source on the page in NS4, you will notice that the text is in different colors. The purple stuff is what it decided was valid HTML. The bold black stuff is what it considered valid attributes. The blue stuff is what it considered valid properties of attributes. The normal stuff is what it considered text. If you see anything blinking, that means it didn't know what it was, and that will usually tell you where it is broken.

    Wherever NS4 sees "script" or "style", it gets cranky. So "javascript" can also give it heartburn and you should split that up as well. For example:

    [font=courier][b]document.write("<script type='text/javascript' language='JavaScript1.2' src='menu-nn.js'></script>");[/b][/font]

    can be split this way:

    [font=courier][b]document.write("<scr" + "ipt type='text/javascr" + "ipt' language='JavaScr" + "ipt1.2' src='menu-nn.js'></scr" + "ipt>");[/b][/font]

    HTH
    Copy linkTweet thisAlerts:
    @Zach_ElfersNov 23.2002 — You can also use this:

    function Browser() {

    if (navigator.appName == "MSIE") {

    document.write("You are using Internet Explorer");

    }

    else {

    if (navigator.appName == "Netscape") {

    document.write("You are using Netscape");

    }

    else {

    document.write("Unknown browser");

    }

    }

    You can redirect the visitor by changing document.write to this.location.href. Hope that helps!

    ?
    Copy linkTweet thisAlerts:
    @silverbobauthorNov 23.2002 — Thanks everyone.

    Zach -

    Doesn't "Function()" need to be in the <head> section?

    You all realize, I hope, that the script I posted all resides in the page <body>.

    Gil -

    I tried your suggestion and nothing changed. Same results.

    Blinking text? I've never seen that. Generally, js errors will show up in the Javascript console.

    What is showing up in my NS7 console is:

    Error: fixit has no properties

    Source File: file:///d:/Webs/symark/_pgtres/stm31.js

    Line: 1635

    This is a different .js file I call in the <head> of this page that's required for this menu script to work.

    While investigating this problem, I ran accross a suggestion to change "<" and ">" to "&lt;" and "&gt;".

    That generally returns this error from NS7:

    Error: unterminated string literal

    Source File: file:///d:/Webs/symark/testnav.htm

    Line: 90, Column: 18

    Source Code:

    document.write("<script type='text/javascript' language='JavaScript1.2' src='menu-ie.js'>;

    NS4 gives me the same error but points to line 88

    And, IE doesn't complain about anything.

    Is any of this helpful information?
    Copy linkTweet thisAlerts:
    @gil_davisNov 23.2002 — [i]Originally posted by silverbob [/i]

    [B]Gil -



    I tried your suggestion and nothing changed. Same results.



    Blinking text? I've never seen that. Generally, js errors will show up in the Javascript console.[/b]
    [/quote]


    Not JS errors, HTML errors (no end tags, bad nesting, etc). NS 4 is strict, and some errors will keep JS from running and you don't get JS errors reported.

    [B]Error: unterminated string literal

    Source File: file:///d:/Webs/symark/testnav.htm

    Line: 90, Column: 18

    Source Code:

    document.write("<script type='text/javascript' language='JavaScript1.2' src='menu-ie.js'>;



    NS4 gives me the same error but points to line 88[/B]
    [/QUOTE]


    Is this a typo? Shouldn't it be:

    [font=courier]document.write("<script type='text/javascript' language='JavaScript1.2' src='menu-ie.js'>");[/font]
    Copy linkTweet thisAlerts:
    @silverbobauthorNov 23.2002 — Yes, I realize you were talking about HTML errors. But, I've never seen blinking text in a "view source" with NS4. Guess I live a sheltered life. ?

    About the typo, I think you're referring to missing spaces. They are there, just not as evident with the font used.
    Copy linkTweet thisAlerts:
    @StefanNov 24.2002 — [i]Originally posted by silverbob [/i]

    I am trying to implement a new navigation menu on a web site.

    Because NS4 renders fonts 1pt smaller than IE, I am using some browser detection to call the appropriate menu.js file.
    [/QUOTE]


    A better way would perhaps be to specify font-size in pixel then?

    No intricate JavaScript needed that might break...

    ?

    BTW, 1px = 1px on ALL OS platforms too. 1pt can vary greatly between eg Win and Mac.

    In short, pt for meadia="screen" is about the worst choise you can make to begin with.
    Copy linkTweet thisAlerts:
    @silverbobauthorNov 24.2002 — What a great idea Stefan. Unfortunately, it doesn't make any difference whether you specify pt or px.

    NS4 still renders the font 1pt or 1px smaller.

    Try it yourself. Write a simple web page, i.e.

    <html>

    <head></head>

    <body>

    <p><font size="10pt">Hello</font>

    <p><font size="10px">Hello</font>

    </body>

    </html>

    Display it in both I.E. and NS4 and measure the length of the word "Hello" in all cases. You'll find that the "Hello"s in NS4 will measure smaller.

    The size is important because I am using images as my top-level menu, and I need the drop-down menus to match in font and size.
    Copy linkTweet thisAlerts:
    @StefanNov 24.2002 — [i]Originally posted by silverbob [/i]

    [B]What a great idea Stefan. Unfortunately, it doesn't make any difference whether you specify pt or px.

    NS4 still renders the font 1pt or 1px smaller.





    Try it yourself. Write a simple web page, i.e.



    <html>

    <head></head>

    <body>

    <p><font size="10pt">Hello</font>

    <p><font size="10px">Hello</font>

    </body>

    </html>



    [/QUOTE]




    Well, time to drop the font crap and take use NS 4 buggy CSS implementation to your advantage ?



    <body>

    <p class="plopp noNS4">Hello</p>

    <p class="plopp noNS4">Hello</p>

    </body>



    .plopp {font-size:11px;}

    .noNS4 {font-size:10px;}







    The size is important because I am using images as my top-level menu, and I need the drop-down menus to match in font and size.
    [/QUOTE]




    Auch... you better hope noone visits your site specifying a non standards preferd text-size (eg due to bad sight). Usually it's better to try to use methods that arn't as easily broken.



    Eg specifying width & hights in ex or em will make boxes etc scale with the size of the font.

    Also, if you can leave sizes content generated you will never run into problems with things not fitting "in their box".
    Copy linkTweet thisAlerts:
    @Zach_ElfersNov 24.2002 — [i]Originally posted by silverbob [/i]

    [B]Thanks everyone.



    Zach -



    Doesn't "Function()" need to be in the <head> section?



    You all realize, I hope, that the script I posted all resides in the page <body>.



    Gil -



    I tried your suggestion and nothing changed. Same results.



    Blinking text? I've never seen that. Generally, js errors will show up in the Javascript console.



    What is showing up in my NS7 console is:



    Error: fixit has no properties

    Source File: file:///d:/Webs/symark/_pgtres/stm31.js

    Line: 1635



    This is a different .js file I call in the <head> of this page that's required for this menu script to work.



    While investigating this problem, I ran accross a suggestion to change "<" and ">" to "&lt;" and "&gt;".



    That generally returns this error from NS7:



    Error: unterminated string literal

    Source File: file:///d:/Webs/symark/testnav.htm

    Line: 90, Column: 18

    Source Code:

    document.write("<script type='text/javascript' language='JavaScript1.2' src='menu-ie.js'>;



    NS4 gives me the same error but points to line 88



    And, IE doesn't complain about anything.



    Is any of this helpful information? [/B]
    [/QUOTE]


    No the function doesn't need to be in the head section. It doesn't really matter much.
    ×

    Success!

    Help @silverbob spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...