Welcome visitor
* Login
* Register
It is currently July 18th, 2019, 5:23 pm
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Client Side » HTML



Post new topic Reply to topic  [ 3 posts ] 
Author Message
  Automatic line break in cell
PostPosted: October 27th, 2009, 9:07 pm 

Posts: 19
Hi, i have a table that is filled dinamically with javascript. But one cell contains an automatically generated link, which sometimes is too big, is there a way to brake that line or hide the excesive lenght of it?


Top
 Profile  
 
  Re: Help with this cell, please
PostPosted: October 27th, 2009, 10:29 pm 
User avatar

Posts: 136
If you wanto to chop the huge string in many parts and then show them in a cell with br between any substring, try this script
<script type="text/javascript">
function  switchcontent()
{
  finalstr = '';
  l=10; //number of characters allowed per line
  originalstr=document.getElementById('thecell').textContent;
  copyoriginal=document.getElementById('thecell').textContent;
  if (copyoriginal.length>=10)
  {
    ltimes=Math.ceil(copyoriginal.length/l);
    for (i=1; i<ltimes; i++)
    {
      finalstr = finalstr + copyoriginal.substr(0,l) + '<br />';
      copyoriginal=copyoriginal.slice(l);
    }
    finalstr = finalstr + copyoriginal;
    replacestr='<a href="'+originalstr+'">'+finalstr+'</a>';
    document.getElementById('thecell').innerHTML=replacestr;
  }
}
</script>
<table><tr>
    <td id="thecell"><a href="http://longlonglonglonglonglonglonglonglong.url">
    http://longlonglonglonglonglonglonglonglong.url</a></td>
</tr></table>
<input type="button" value="add breaklines" onclick="switchcontent();" />
hth


Top
 Profile  
 
  Re: Automatic line break in cell
PostPosted: October 27th, 2009, 10:56 pm 

Posts: 96
This would be to make your cell stay always the same size.

The CSS
<style type="text/css">
.fixedtable{table-layout:fixed;overflow:hidden; width: 100px} 
.fixedcell{white-space:nowrap;overflow:hidden; width: 50px}
</style>

And the HTML
<table class="fixedtable"><tr>
    <td class="fixedcell"><a href="http://longlonglonglonglonglonglonglonglong.url">
    http://longlonglonglonglonglonglonglonglong.url</a></td><td>next col</td>
</tr></table>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

FORUMS » Client Side » HTML


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron