Go Back   CodingForums.com > Web Projects and Services Marketplace > Web Projects > Small projects (quick fixes and changes)

Notices

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-02-2010, 01:13 PM   PM User | #1
tpeck
Regular Coder

 
tpeck's Avatar
 
Join Date: Oct 2002
Location: Sydney, Australia
Posts: 780
Thanks: 41
Thanked 5 Times in 4 Posts
tpeck is on a distinguished road
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)
tpeck is offline   Reply With Quote
Old 11-03-2010, 09:17 AM   PM User | #2
tpeck
Regular Coder

 
tpeck's Avatar
 
Join Date: Oct 2002
Location: Sydney, Australia
Posts: 780
Thanks: 41
Thanked 5 Times in 4 Posts
tpeck is on a distinguished road
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)
tpeck is offline   Reply With Quote
Old 11-03-2010, 07:17 PM   PM User | #3
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
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..
MattF is offline   Reply With Quote
Old 11-07-2010, 07:03 AM   PM User | #4
tpeck
Regular Coder

 
tpeck's Avatar
 
Join Date: Oct 2002
Location: Sydney, Australia
Posts: 780
Thanks: 41
Thanked 5 Times in 4 Posts
tpeck is on a distinguished road
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)
tpeck is offline   Reply With Quote
Old 11-07-2010, 12:46 PM   PM User | #5
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
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.
MattF is offline   Reply With Quote
Old 11-07-2010, 02:57 PM   PM User | #6
tpeck
Regular Coder

 
tpeck's Avatar
 
Join Date: Oct 2002
Location: Sydney, Australia
Posts: 780
Thanks: 41
Thanked 5 Times in 4 Posts
tpeck is on a distinguished road
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)
tpeck is offline   Reply With Quote
Old 11-07-2010, 03:16 PM   PM User | #7
tpeck
Regular Coder

 
tpeck's Avatar
 
Join Date: Oct 2002
Location: Sydney, Australia
Posts: 780
Thanks: 41
Thanked 5 Times in 4 Posts
tpeck is on a distinguished road
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)
tpeck is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:38 PM.


Advertisement
Log in to turn off these ads.