Compatibility Issue in certain mobile browsers

Hi.

I have this script to remove a “button” id when a certain word (“registered”) is in a table cell.

The code:

<script> 	
  var allTableCells = document.getElementsByTagName("td");
  for(var i = 0, max = allTableCells.length; i < max; i++) {
    var node = allTableCells[i];
    var currentText = node.childNodes[0].nodeValue; 
    if (currentText === "registered")
    document.getElementById("button").remove();
  }
</script>

It works fine in almost every browser but in some mobile version in iPhone, Nokia and some others in Windows mobile. I have tested it including some modifications with no result.

Could someone tell me if there is some mistake or whatever might be causing this failure?

Thanks.

The code looks good. Does a test page with only the above code (and some td’s to test with) also fail?
If so, can you give us more information about the specific environments in which it does fail.

Ok. I’ll do it.

Many thanks Paul.

Whilst it may not be the cause of the issue, I’d suggest wrapping curly braces ( {} ) around your if statement like so…

<script>
  var allTableCells = document.getElementsByTagName("td");
  for(var i = 0, max = allTableCells.length; i < max; i++) {
    var node = allTableCells[i];
    var currentText = node.childNodes[0].nodeValue; 
    if (currentText === "registered") {
      document.getElementById("button").remove();
    }
  }
</script>

No, it wasn’t about the braces.

I have tested it on diverse ways and the result is the same in iPhone 5 with IO6, Nokia Luminia 930 and some others.

Any suggestion or other way to get to the removal if “registered” is into the td?

Thanks.

I’ve put together a simple test that we can use to check if the code works properly on different browsers.

Do the mobile devices have the same trouble on that test page?

If they do, we can check things further based on the mobile browser that’s being used.

If those mobile browsers don’t have trouble with the test page, then the most likely cause is that it’s something else on the more complex page that’s failing, preventing JavaScript execution from carrying on to execute the above code.

The test does not remove the button. The code does not work in those mobiles either.

Sorry guys, the problem is not in the function but here:

document.getElementById("button").remove();

It is not supported by some mobile browsers.

And the solution was in this superb forum:

With this other script it works:

var d = document.getElementById("the-div");
if (d) { d.parentNode.removeChild(d); }

Thanks (and solved).

4 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.