0

I am trying to allow the user to click anywhere in the row and to trigger a link, following the instructions there: Adding an onclick event to a table row.

This works fine with the following generated code inside the WebView:

h += "<script>\r\n" +
        "function HandleTable(table) {\r\n" + 
        "    var rows = table.getElementsByTagName(\"tr\");\r\n" + 
        "    for (i = 0; i < rows.length; i++) {\r\n" + 
        "        var currentRow = table.rows[i];\r\n" + 
        "        var createClickHandler = \r\n" + 
        "            function(row) \r\n" + 
        "            {\r\n" + 
        "                return function() { \r\n" + 
        "                      var cell = row.getElementsByTagName(\"td\")[0];\r\n" + 
        "                      var id = cell.innerHTML;\r\n" + 
        "                      window.location.href = id;\r\n" + 
        "                  };\r\n" + 
        "            };\r\n" + 
        "\r\n" + 
        "        currentRow.onclick = createClickHandler(currentRow);\r\n" + 
        "    }\r\n" + 
        "}";

And then putting the table like that:

        h += "<table width=\"100%\" id=\"tbl\" class=\"...\">";

And the script:

        h += "<script>\r\n";
    h += "var t = document.getElementById(\'tbl\');\r\n";
    h += "HandleTable(t);\r\n";
    h += "</script>\r\n";

Then I load the String h to the WebView. This works fine in my 4.0.x tablet, but NOT in my 4.4 phone.

Do I miss something for KitKat?

Thanks.

Community
  • 1
  • 1
Michael Chourdakis
  • 10,345
  • 3
  • 42
  • 78

1 Answers1

0

Found the problem, it seems that KitKat returns invalid content for cell.innerHTML for a reason.

Switched to

<tr onclick="window.location.href='test'">

instead.

Michael Chourdakis
  • 10,345
  • 3
  • 42
  • 78