javascript - Internet Explorer 8 & 7 is converting tabs to spaces -


i'm trying use javascript jquery convert tab delimited string html table.

in input string rows separated <br/> , columns tabs.

here's have far:

  $(function(){     $('div.jstable').each(function(){        var text = $(this).html();       var rows = text.split(/<br>/i);       var htmlstring = "<table class='display datatable'>"       var starttbody = true;       for(i = 0; i< rows.length; i++){         // build header section         if (i == 0){           htmlstring += '<thead>';         }else {           if (starttbody){             htmlstring += '<tbody>';             starttbody = false;           }         }         htmlstring += '<tr>';          var row = rows[i];         var columns = row.split('\t');          // build columns         (j = 0; j < columns.length; j++ ){           if (i == 0){             htmlstring += '<th>' + columns[j] + '</th>';           }else {             htmlstring += '<td>' + columns[j] + '</td>';           }         }          htmlstring += '</tr>';         if (i == 0){           htmlstring += '</thead>'         } else {           if (i == rows.length - 1){             htmlstring += '</tbody>'           }         }       }       htmlstring += '</table>';       $(this).html(htmlstring);     })   }); 

and here input text:

  <div class="jstable" style="float: left"> col1    col2    col3<br />asda  fd  dfs<br />mmmm   ffff    ssss   </div> 

unfortunately in ie8/7 text returned jquery .html() function has tabs replaced spaces.

ie9 fine, current versions of firefox & chrome work fine.

any ideas?

you can pass regular expression split(). /\s+/ consider consecutive whitespace of kind single delimiter:

>>> "one   two".split(/\s+/) ["one", "two"]  >>> "one\ttwo".split(/\s+/) ["one", "two"]  >>> "one\ntwo".split(/\s+/) ["one", "two"] 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -