SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Aug 2005
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to show JS only in print

    Anyone know a way to only run JS when the user prints? I have this script which outputs links but I only want it to work when the user prints.

    It would be better to use CSS but IE doesn't get genrated content.

    Steven

    Code:
    window.onload = displayLinks;
    
    function displayLinks() {
      var links = document.getElementsByTagName("a");
       
      for (var i=0; i<links.length; i++) {
        var current_link = links[i];
    	var href = current_link.getAttribute("href");
    	//var key = current_link.lastChild.nodeValue;	
    	
    	var href_text = document.createTextNode(href);
    	current_link.appendChild(href_text);	
    	current_link.className = "print-link";
      }

  2. #2
    malloc
    Join Date
    Nov 2006
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would suggest the most robust way to do this would be to have a "printer friendly" button/link which displays the printable version using CSS/JS/Whatever.

    I'm not sure all browsers would even bother running JS if they're going to print a page - not sure though.


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
  •