SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2004
    Location
    usa
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    converting links to URL/URIs when printing

    does anyone know of a script that automatically converts inline text links to the actual URL when the documented is printed?

    thank you :-)

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    CSS does the trick for non-IE browsers.
    Code:
    a:after {
      content: attr(href);
    }
    You can try this bit of javascript for IE, but I'm not sure it will work:
    Code:
    //caution: code is untested
    onbeforeprint = function ()
    {
      var links = document.getElementsByTagName("a");
      var i = 0, thislink;
      while (thislink = links[i++])
      {
        var tn = document.createTextNode(thislink.getAttribute("href"));
        thislink.appendChild(tn);
      }
    }
    Assuming that function works, you'd have to create another function for IE's onafterprint event handler to restore the links back to their original states (without the href in the link text).

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2004
    Location
    usa
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks vinnie, but i'm afraid that is a bit over my head. and wouldn't that display them onscreen as well?

    as a guess, though, could i do it as onprint rather than onbeforeprint so they would dipslay as normal links onscreen and i would not have to have the afterprint code?

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by mtouchette
    thanks vinnie, but i'm afraid that is a bit over my head. and wouldn't that display them onscreen as well?
    For the CSS part, not if you put it in a print-media stylesheet. Example:
    HTML Code:
    <style type="text/css" media="print">
    <!--
    a:after {
      content: attr(href);
    }
    -->
    </style>
    This will show whatever the HREF attribute is for the link on the printed page but keep it offscreen.
    as a guess, though, could i do it as onprint rather than onbeforeprint so they would dipslay as normal links onscreen and i would not have to have the afterprint code?
    If you set them onprint, you still have to remove them after printing. I prefer using the onbeforeprint event, but feel free to try onprint.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •