Announcement

Collapse
No announcement yet.

Netscape Strikes again

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Netscape Strikes again

    The javascript code below swaps a LOG IN and LOG OUT image depending on the contents of a field elsewhere.

    This works a treat in Internet Explorer (v4.01 and above), but in Netscape and FireFox it only displays the LOG OUT button.

    Are the any Netscape bods out there who can tell me why Netscape always goes down the first logic path and shows the LOG OUT button?

    Is it something to do with the innerHTML tag?

    Many thanks,
    Dave

    www.youraromatherapy.co.uk

    ---
    function SwitchLoginButton()
    {
    if (document.getElementById('pnMemberName') != null)
    {
    if (document.getElementById('pnMemberName').innerHTML.length > 30)
    {
    document.getElementById('pnLogout').style.display = 'block';
    document.getElementById('pnLogin').style.display = 'none';
    }
    else
    {
    document.getElementById('pnLogout').style.display = 'none';
    document.getElementById('pnLogin').style.display = 'block';
    }
    }
    }
    ---

    #2
    Try adding some diagnostic code to display what's in that field.
    Code:
    alert(document.getElementById('pnMemberName').innerHTML.length + ' - ' + document.getElementById('pnMemberName').innerHTML);
    Also Netscape will not see a getElementById if you've only used a name="pnMemberName" tag. You have to have an id="pnMemberName" as well.

    IE is a bit more relaxed and will treat the "name=" as an "id=" if the id tag isn't there.
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      Thanks for the advice Norman.

      Within the span tag, Internet explorer puts <ACTINIC:CURRACOUNT /> whereas Netscape/Firefox puts <actinic:curracount></actinic:curracount>, hence the error.

      That kinda scuppers the use of a 30 character check on the innerHTML.

      Any ideas Norman?

      I want to display the LOG IN block when no-one is logged in, and LOG OUT when someone is logged in, and the above method seemed the quickest and easiest way to achieve that...

      Comment


        #4
        I presume the logged in pages show a user name here and the logged out show the <actinic...> tags. Why not test for the string CURRACCOUNT case insensitive using something like
        Code:
        if ( document.getElementById('pnMemberName').innerHTML.search(/curraccount/i) > -1 ) .....
        However there is already a built-in (back-to-front-kind-of) way of telling whether your logged in or not. See the Help or Advanced Guide for <ACTINIC:NOTINB2B>...</ACTINIC:NOTINB2B> where code between these tags gets executed if you are NOT logged in. Here's how I use that (this code has been ticking over in NorTree and NorCascade for years) - I put the following in the HEAD of Act_primary.html.
        Code:
        <script language=JavaScript>var LoggedIn = true;</script>
        <Actinic:NOTINB2B>
        <script language=JavaScript>var LoggedIn = false;</script>
        </Actinic:NOTINB2B>
        If you are logged in the scripts remove the tagged code before spitting it out to the customers browser so only the first line gets executed, setting LoggedIn to true.

        If you are not logged in the scripts don't intervene and both lines get executed leaving LoggedIn false (the <actinic...> tags are simply ignored by the browser).

        Now all your pages have a nice global JavaScript variable indicating LoggedIn status.
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment

        Working...
        X