»
AnglaisFran�aisVietnamien

Imprimer - Tronque HTML Texte - JavaScriptBank.com

Version compl�te: jsB@nk » Texte » Tronque HTML Texte
URL: https://www.javascriptbank.com/truncate-html-text.html

Tronque HTML Texte © JavaScriptBank.comCet JavaScript est une façon intelligente de tronquer automatiquement le texte d'un paragraphe sur votre page Web, sans division, au milieu d'un mot. Vous pouvez tronquer le texte à une longueur de votre choix. Un JavaScript lien est ajoutée pour élargir le texte.

Version compl�te: jsB@nk » Texte » Tronque HTML Texte
URL: https://www.javascriptbank.com/truncate-html-text.html



JavaScript
<script type="text/javascript">// Created by: Patrick Fitzgerald | http://www.barelyfitz.com/function truncate() {  var len = 100;  var p = document.getElementById('truncateMe');  if (p) {    var trunc = p.innerHTML;    if (trunc.length > len) {      /* Truncate the content of the P, then go back to the end of the         previous word to ensure that we don't truncate in the middle of         a word */      trunc = trunc.substring(0, len);      trunc = trunc.replace(/w+$/, '');      /* Add an ellipses to the end and make it a link that expands         the paragraph back to its original size */      trunc += '<a href="#" ' +        'onclick="this.parentNode.innerHTML=' +        'unescape(''+escape(p.innerHTML)+'');return false;">' +        '<span style="font-size: 10px;">[ more ... ]</span></a>';      p.innerHTML = trunc;    }  }}// Multiple onload function created by: Simon Willison// http://simon.incutio.com/archive/2004/05/26/addLoadEventfunction addLoadEvent(func) {  var oldonload = window.onload;  if (typeof window.onload != 'function') {    window.onload = func;  } else {    window.onload = function() {      if (oldonload) {        oldonload();      }      func();    }  }}addLoadEvent(function() {  truncate();});</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<p id="truncateMe">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean consectetuer. Etiam venenatis. Sed ultricies, pede sit amet aliquet lobortis, nisi ante sagittis sapien, in rhoncus lectus mauris quis massa. Integer porttitor, mi sit amet viverra faucibus, urna libero viverra nibh, sed dictum nisi mi et diam. Nulla nunc eros, convallis sed, varius ac, commodo et, magna. Proin vel risus. Vestibulum eu urna. Maecenas lobortis, pede ac dictum pulvinar, nibh ante vestibulum tortor, eget fermentum urna ipsum ac neque. Nam urna nulla, mollis blandit, pretium id, tristique vitae, neque. Etiam id tellus. Sed pharetra enim non nisl.</p><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->