/    Sign up×
Community /Pin to ProfileBookmark

crossbrowser version of a textarea printout

Is anyone able to make this code crossbrowser? Can it actually be done?

It brings up the print dialog box and will print out the contents of a textarea box, but only in IE.

[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();
}[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@tpeckauthorNov 03.2010 — Oops! I have discovered that I tested incorrectly and it DOES work in FF after all. It loads up a new window and prints the contents of the new window.

But the routine falls over in Chrome.

What is Chrome objecting to do you think?
Copy linkTweet thisAlerts:
@aj_nscNov 03.2010 — Oops! I have discovered that I tested incorrectly and it DOES work in FF after all. It loads up a new window and prints the contents of the new window.

But the routine falls over in Chrome.

What is Chrome objecting to do you think?[/QUOTE]


When you load up your page in chrome, push CTRL+Shift+J to open up the console. Then do whatever you do to start the routine and check your console (the thing that opened up when you pushed CTRL+Shift+J) and you should see an error message.
Copy linkTweet thisAlerts:
@tpeckauthorNov 05.2010 — Thanks - that is very helpful!
×

Success!

Help @tpeck spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...