Opera and Mozilla javascript differences

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abarrett79
    New Member
    • May 2007
    • 2

    Opera and Mozilla javascript differences

    I'm having problems with a javascript bookmarklet to scrape data off a webpage. The code runs as planned in Opera, but fails in FireFox.

    In all it's one lined glory
    Code:
    javascript:temp=prompt("Please enter Building Coordinates\nExample: 0,0");output=temp+",";size=document.getElementsByName("main")[0].contentDocument.getElementsByTagName("table")[6].cells.length;numcommods=(size-10)/7;cel=6;for (m=1; m<=numcommods; m++){for (n=1;n<=5;n++){output += document.getElementsByName("main")[0].contentDocument.getElementsByTagName("table")[6].cells[cel].innerHTML+",";cel++;};output+=document.getElementsByName("main")[0].contentDocument.getElementsByTagName("table")[4].cells[(m*5)+1].innerHTML+",";cel+=2;};location.href="http://71.205.48.105/pardus/bookmarklet.php?data="+encodeURIComponent(output);
    Formatted for readability
    Code:
    javascript:temp=prompt("Please enter Building Coordinates\nExample: 0,0");
    output=temp+",";
    size=document.getElementsByName("main")[0].contentDocument.getElementsByTagName("table")[6].cells.length;
    numcommods=(size-10)/7;
    cel=6;
    for (m=1; m<=numcommods; m++) {
      for (n=1;n<=5;n++) {
        output += document.getElementsByName("main")[0].contentDocument.getElementsByTagName("table")[6].cells[cel].innerHTML+",";
        cel++;};
      output+=document.getElementsByName("main")[0].contentDocument.getElementsByTagName("table")[4].cells[(m*5)+1].innerHTML+",";
      cel+=2;};
    location.href="http://71.205.48.105/pardus/bookmarklet.php?data="+encodeURIComponent(output);
    Any help, even a link to a relevant page, or topics to search for, would be greatly appreciated.
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    whats the errors its throwing.

    location.href=

    should probably be
    window.location =

    and
    numcommods=(siz e-10)/7;
    could be
    numcommods=Math .floor(size-10)/7;

    wheres it failing is where i'm going with this

    Comment

    • abarrett79
      New Member
      • May 2007
      • 2

      #3
      I found the error that was bringing down the house. Opera has what appears to be an extension to DOM. getElementsByTa gName("table"). cells is valid in opera, but not firefox. I replaced it with:
      getElementsByTa gName("table"). getElementsByTa gName("td")

      With a couple adjustments to positioning in the results array, all is well.

      Thank you anyway

      Comment

      Working...