Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Netscape onclick attribute does not work in NS4

    I would like to have a text with an onclick attribute that executes something when clicked. The following solution works in Internet Explorer and Netscape6 but does not work in Netscape4:

    <div onclick="action()">
    Click here
    </div>

    Does anyone have a solution for achieving this in Netscape4?

    Thank you.

  • #2
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    You'd have to surround the Div with a link, i'd say. NS4 only supports certain events on certain elements. I rely on a table in the Guide (see my sig) to see which elements support which events in which browsers.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Netscape 4 version browsers do not support the onClick in a div tag. You could place some javascript withing the div to check for NS4 and write a link. Something like this:
    <DIV>
    <SCRIPT LANGUAGE="JavaScript">
    if(document.layers)
    {
    document.write("<A HREF='page.html'>Click Here</A>")
    }
    </SCRIPT>
    </DIV>

    The above would only write that out if the browser was NS4. Also make sure that you use single quotes within double quotes.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My first example was not very good. Try this one (hopefully it is better).
    <html>
    <head>
    <title>Onclick in a div</title>
    <SCRIPT LANGUAGE="JavaScript">
    function doalert() {
    alert("This worked!")
    }
    </SCRIPT>
    </head>
    <body>
    <DIV ID="mydiv" onClick="doalert()">
    <SCRIPT LANGUAGE="JavaScript">
    if(document.layers)
    {
    document.write("<A HREF='javascript:doalert()'>Click Here</A>")
    }
    else
    {
    document.write("Click Here")
    }
    </SCRIPT>
    </DIV>
    </body>
    </html>

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    If it is just text you want to click why not just use a normal anchor?

    <a href="placetogo.htm" class="myclass">the text here</a>

    then in a style sheet you could say how you wanted "myclass" to look.

    If you can explain more of what you are trying to do, we can be of more help.

  • #6
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Netscape

    Thank you for your suggestions.
    In fact, what I want to do is a table whose rows can be selected, in the sense that they are highlighted when clicked and the clicked row number is memorized. I tried to put the whole row in an anchor, but this does not work, it only works with individual table data (td elements). Isn't there a simpler solution?

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    'Simple' and 'Navigator' probably don't belong in the same sentence - anyway, see what you can make of this:


    <html>
    <head>
    <title>untitled</title>
    <style type="text/css">

    .rowOFF{
    background: #990000;
    cursor: hand;
    }

    .rowON {
    background: #cc0000;
    cursor: hand;
    }

    .NScell {
    padding-top: 3px;
    }

    a {
    font: 400 16px "times new roman";
    color: #ffeeee;
    text-decoration: none;
    }

    </style>
    <script type="text/javascript" language="javascript">

    var NS_off_bgcolor = '#990000';
    var NS_on_bgcolor = '#cc0000';

    function hilite_row(row) {
    if (!document.layers) row.className = (row.className == 'rowOFF') ? 'rowON' : 'rowOFF';
    else {
    var l, Ypos = document.anchors[row].y;
    for (var i=0; i<document.layers.length; ++i) {
    l = document.layers[i];
    if (l.pageY == Ypos) {
    l.bgColor = (l.lit) ? NS_off_bgcolor : NS_on_bgcolor;
    l.lit = !l.lit;
    }
    }
    }
    }

    </script>
    </head>
    <body bgcolor="#550000">
    <div align="center" style="padding-top:20px;">
    <table cellspacing="1" cellpadding="0" border="2">
    <tr id="ROW_0" class="rowOFF" onclick="hilite_row(this)">
    <td><a href="javascript&#58;void hilite_row('ROW_0')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 0 CELL 1&nbsp;</ilayer></a><a name="ROW_0"></td>
    <td><a href="javascript&#58;void hilite_row('ROW_0')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 0 CELL 2&nbsp;</ilayer></a></td>
    <td><a href="javascript&#58;void hilite_row('ROW_0')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 0 CELL 3&nbsp;</ilayer></a></td>
    <td><a href="javascript&#58;void hilite_row('ROW_0')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 0 CELL 4&nbsp;</ilayer></a></td>
    </tr>
    <tr id="ROW_1" class="rowOFF" onclick="hilite_row(this)">
    <td><a href="javascript&#58;void hilite_row('ROW_1')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 1 CELL 1&nbsp;</ilayer></a><a name="ROW_1"></td>
    <td><a href="javascript&#58;void hilite_row('ROW_1')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 1 CELL 2&nbsp;</ilayer></a></td>
    <td><a href="javascript&#58;void hilite_row('ROW_1')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 1 CELL 3&nbsp;</ilayer></a></td>
    <td><a href="javascript&#58;void hilite_row('ROW_1')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 1 CELL 4&nbsp;</ilayer></a></td>
    </tr>
    <tr id="ROW_2" class="rowOFF" onclick="hilite_row(this)">
    <td><a href="javascript&#58;void hilite_row('ROW_2')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 2 CELL 1&nbsp;</ilayer></a><a name="ROW_2"></td>
    <td><a href="javascript&#58;void hilite_row('ROW_2')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 2 CELL 2&nbsp;</ilayer></a></td>
    <td><a href="javascript&#58;void hilite_row('ROW_2')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 2 CELL 3&nbsp;</ilayer></a></td>
    <td><a href="javascript&#58;void hilite_row('ROW_2')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 2 CELL 4&nbsp;</ilayer></a></td>
    </tr>
    </table>
    </div>
    </body>
    </html>


    Uses an anchor to get the row position. Whatever.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •