Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    882
    Thanks
    53
    Thanked 6 Times in 5 Posts

    notepad printout

    Hi. I require a cross browser version of this code:

    Code:
    /*
    for notepad printouts
    */
    function printInput(f){
      var ifr = window.frames['printFrame'];
      if (ifr){ //print the content of the invisible iframe
         ifr.document.getElementById('content').innerHTML=f.WRKNOTEPAD.value.replace(/\n/g,'<br />');
         ifr.focus();
         ifr.print();
      }
      else { //print by opening a new window and then closing it
         var html='<html><head><style type="text/css">div{font:normal 14px Verdana}</style></head><body onload="window.print();window.close()"><div>'+f.WRKNOTEPAD.value.replace(/\n/g,'<br />');+'</div></body></html>'
         var win = window.open('','_blank','menubar,scrollbars,resizable');
         win.document.open();
         win.document.write(html);
         win.document.close();
      }
    }
    
    function writeContent(objIframe){
      var html='<html><head><style type="text/css">div{font:normal 14px Verdana}</style></head><body><div id="content"></div></body></html>'
      objIframe.document.write(html);
      objIframe.document.close();
    }
    Anyone up for it?

    It prints the contents of a textarea.

    If you need a demo in INTERNET EXPLORER (which works), please ask.

    It fails in all the other crap browsers.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #2
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    882
    Thanks
    53
    Thanked 6 Times in 5 Posts
    It's extraordinary, but this post I made late last night is appearing automatically in another website!

    Is there some leeching going on? It links back to this page!

    Should I advise someone?

    http://www.entrepreneur-univ.com/ans...pad-printout/#

    Weird...
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #3
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    That site has been doing that trick for a few weeks at least. Noticed the same thing with a post I made the other week. It wasn't linking back to source then though. It was behaving as if the content was local.


    Btw, are you sorted with the JS yet?
    Last edited by MattF; 11-03-2010 at 10:07 PM.

  • #4
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    882
    Thanks
    53
    Thanked 6 Times in 5 Posts
    Sorry Matt, I have been busy with other things. Weird site - it's not the only one either - here's another:

    http://www.jqueryhome.com/crossbrows...-printout.html

    As for the notepad script, it works in IE only. I might be being a bit harsh in the other browsers because from my investigations, it appears this might be a rare case of IE getting it right for once!

    In FF, apart from the fact that it fails to load up the print dialog box, there is a problem in that the textarea box has to be expanded before all the textarea contents will print out (so I read). There is a routine I found which does just that, but it prints out the entire webpage - not just the textarea contents:

    Code:
    function printNodes()
    {
      var taArray = document.getElementsByTagName('WRKNOTEPAD');
      for(count=0;count<taArray.length;count+=1)
      {
          taArray[count].style.height = 0;
          taArray[count].style.height = (taArray[count].scrollHeight+7) + "px";
      }
      window.print();
    }
    Please let me know if you wish to tackle making this crossbrowser!
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #5
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Any chance of a link to a working example of a page which has the content you want to print? If you could PM me the link, I'll have a peek at it.

  • #6
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    882
    Thanks
    53
    Thanked 6 Times in 5 Posts
    This cut down page was working before (in IE) but for some reason I can't get it happening in IE either today.

    http://aapress.com.au/02.basichints/lesson1/LESSON1try.html

    In FF it is supposed to bring up a window first. Not today. I must have messed something. Grrr.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #7
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    882
    Thanks
    53
    Thanked 6 Times in 5 Posts
    My demo link works now - I had been fiddling about with the form name.

    Basically, this works in IE and FF but not Chrome or Safari.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)


  •  

    Posting Permissions

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