Truncate hyperlink automatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sivapriyan
    New Member
    • Jun 2007
    • 4

    Truncate hyperlink automatically

    Hello I want to show some 10 of my Hyperlinks in a box in right side of my page
    My problem is hyperlink is so long, so i want to show dot(...) at the end of the line. I dont want to extend the hyperlink to the second link so please any one help me with the code
  • Suudsu2200
    New Member
    • Mar 2007
    • 17

    #2
    My guess would be to write








    <a href="your URL">your URL untill it gets too long and then you put ...</a>

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      hi ...

      have a look at the following example and play with it ;) (in case you want to create your list dynamically)

      [HTML]<script>
      function create_link_lis t() {
      var url_list = {
      1: 'verylongurltod isplay.html',
      2: 'http://www.google.de',
      3: 'veryverylongur ltodisplay.html '
      };

      var link_container = document.getEle mentById('link_ list');

      for (var i in url_list) {
      var url = url_list[i];

      var line_break = document.create Element('br');
      var anchor_element = document.create Element('a');
      anchor_element. href = url;

      var url_txt = url;

      if (url_txt.length > 20) {
      url_txt = url.match(/(.{17})/)[1] + '...';
      }
      anchor_element. innerText = url_txt;

      link_container. appendChild(anc hor_element);
      link_container. appendChild(lin e_break);
      }
      }
      </script>

      <body onload="create_ link_list()">
      <div id="link_list"> </div>
      </body>[/HTML]

      hope this helps, and

      kind regards ...

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Changed thread title.

        Comment

        Working...