/    Sign up×
Community /Pin to ProfileBookmark

Print one area of page… IE, good… Firefox, problems.

Hi guys,

Would really appreciate your help with something. I’m trying to isolate an area of a long WordPress page to print. I’ve come across a script which actually does an excellent job in IE but not in FF. Firefox doesn’t want to know for some reason. Is there anything you can see from the following that would be causing FF to have headaches?

Script:

[CODE]function printURL(sHref) {
if(document.getElementById && document.all && sHref){
if(!self.oPrintElm){
var aHeads = document.getElementsByTagName(‘HEAD’);
if(!aHeads || !aHeads.length)
return false;
if(!self.oPrintElm)
self.oPrintElm = document.createElement(‘LINK’);
self.oPrintElm.rel = ‘alternate’;
self.oPrintElm.media = ‘print’;
aHeads[0].appendChild(self.oPrintElm);
}
self.oPrintElm.href = sHref;
self.focus();
self.print();
return true;
}
else return false;
}[/CODE]

Body:

[CODE]<a onclick=”printURL(this.href); return false;” href=”#” target=”_blank”>print</a>[/CODE]

With that above I can target right down to even printing, in isolation, just an image, so it’s a real winner as I have coupons on the page that I want printed in isolation, but Firefox just plays dumb when I hit the ‘print’ button. Would really appreciate your thoughts.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@DracoMerestAug 28.2011 — if(document.getElementById [COLOR="Blue"]&amp;&amp; document.all[/COLOR] &amp;&amp; sHref){

The blue text specifically excludes most browsers.

I'd even go as far to say that it will exclude ALL browsers except Internet Explorer.
Copy linkTweet thisAlerts:
@waterprismauthorAug 28.2011 — if(document.getElementById [COLOR="Blue"]&amp;&amp; document.all[/COLOR] &amp;&amp; sHref){

The blue text specifically excludes most browsers.

I'd even go as far to say that it will exclude ALL browsers except Internet Explorer.[/QUOTE]


Yeah, okay, thanks. I think it's back to the drawing board on this one.
×

Success!

Help @waterprism 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...