[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

OT : min. requirements for printing web page content

Mike Scirocco

4/6/2016 2:06:00 AM

I have to print parts of a web page using javascript, and I'm wondering
what the minimum requirements are for printing. Normally I print a whole
valid page to a new window including css, then print it. Is there a
reliable way to do less? Iow can I ignore everything but the content I
want to print and use html tags to formate it, like maybe just
formatting the content in a new div and printing that?

TIA,
Mike S
6 Answers

ram

4/6/2016 2:33:00 AM

0

Mike S <mscir@yahoo.com> writes:
>Iow can I ignore everything but the content I
>want to print and use html tags to formate it, like maybe just
>formatting the content in a new div and printing that?

Yes. Copy the content to a new window. »w = window.open ...«,
»w.write( contents )«, »w.print ...«.

If you have a popup-blocker: Use a custom css for printing,
which will hide everything but the content.

Or: Save the old document in a variable. Replace document by
content. Print. Restore old document.

In jQuery, see »printElement«.

Mike Scirocco

4/6/2016 7:00:00 AM

0

On 4/5/2016 7:33 PM, Stefan Ram wrote:
> Mike S <mscir@yahoo.com> writes:
>> Iow can I ignore everything but the content I
>> want to print and use html tags to formate it, like maybe just
>> formatting the content in a new div and printing that?
>
> Yes. Copy the content to a new window. »w = window.open ...«,
> »w.write( contents )«, »w.print ...«.
>
> If you have a popup-blocker: Use a custom css for printing,
> which will hide everything but the content.
>
> Or: Save the old document in a variable. Replace document by
> content. Print. Restore old document.
>
> In jQuery, see »printElement«.
>
printElement looks good.

http://www.bennadel.com/blog/1591-ask-ben-print-part-of-a-web-page-with-...

Thanks!
Mike

Teodor V.

4/6/2016 9:42:00 AM

0

On 2016-04-06 09:00, Mike S wrote:
> On 4/5/2016 7:33 PM, Stefan Ram wrote:
>> Mike S <mscir@yahoo.com> writes:
>>> Iow can I ignore everything but the content I
>>> want to print and use html tags to formate it, like maybe just
>>> formatting the content in a new div and printing that?
>>
>> Yes. Copy the content to a new window. »w = window.open ...«,
>> »w.write( contents )«, »w.print ...«.
>>
>> If you have a popup-blocker: Use a custom css for printing,
>> which will hide everything but the content.
>>
>> Or: Save the old document in a variable. Replace document by
>> content. Print. Restore old document.
>>
>> In jQuery, see »printElement«.
>>
> printElement looks good.
>
> http://www.bennadel.com/blog/1591-ask-ben-print-part-of-a-web-page-with-...

FWIW, the CSS approach is the most compatible for users who fly with
Javascript disabled.
I use it the pages I design, minimal CSS and formatting, just enough to
produce a clean printout.

/Teo.


--
Teodor Väänänen | Don't meddle in the affairs of wizards,
teostupiditydor@algonet.se | for you are good and crunchy with
Remove stupidity to reply | ketchup.

Aleksandro

4/6/2016 1:58:00 PM

0

On 06/04/16 06:41, Teodor V. wrote:
> On 2016-04-06 09:00, Mike S wrote:
>> On 4/5/2016 7:33 PM, Stefan Ram wrote:
>>> Mike S <mscir@yahoo.com> writes:
>>>> Iow can I ignore everything but the content I
>>>> want to print and use html tags to formate it, like maybe just
>>>> formatting the content in a new div and printing that?
>>>
>>> Yes. Copy the content to a new window. »w = window.open ...«,
>>> »w.write( contents )«, »w.print ...«.
>>>
>>> If you have a popup-blocker: Use a custom css for printing,
>>> which will hide everything but the content.
>>>
>>> Or: Save the old document in a variable. Replace document by
>>> content. Print. Restore old document.
>>>
>>> In jQuery, see »printElement«.
>>>
>> printElement looks good.
>>
>> http://www.bennadel.com/blog/1591-ask-ben-print-part-of-a-web-page-with-...
>
> FWIW, the CSS approach is the most compatible for users who fly with
> Javascript disabled.
> I use it the pages I design, minimal CSS and formatting, just enough to
> produce a clean printout.

I would never trust Javascript for such a thing, an appropriate CSS
query is the correct way to do it.

Thomas 'PointedEars' Lahn

4/6/2016 6:22:00 PM

0

Stefan Ram wrote:

> Mike S <mscir@yahoo.com> writes:
>>Iow can I ignore everything but the content I
>>want to print and use html tags to formate it, like maybe just
>>formatting the content in a new div and printing that?
>
> Yes. Copy the content to a new window. »w = window.open ...«,
> »w.write( contents )«, »w.print ...«.

Bad idea, for resource usage and:

> If you have a popup-blocker: Use a custom css for printing,
^^^^^^^^^^^^^
> which will hide everything but the content.

More precisely, the better idea is to use a *print stylesheet*, one that is
only triggered if the media is â??printâ?. This is a CSS feature and is not
related to scripting. CSS is on-topic in
<news:comp.infosystems.www.authoring.stylesheets>.

OP: It is outright rude to start a thread in a newsgroup *knowing or
assuming* that it is going to be off topic. You are not going to elicite
answers this way, not many competent ones at any rate, as you are wasting
peopleâ??s free time. People have subscribed here because they are interested
in the topic of *this* newsgroup. If you have difficulty finding the
appropriate newsgroup, there are newsgroups like
<news:news.newusers.questions> where you can ask about that. You can even
ask in a newsgroup in which the thread is likely off-topic where it would be
on-topic. But it does not work as you did. Please read the FAQ of this
newsgroup on how to post properly, and do not do again what you did.

> Or: Save the old document in a variable. Replace document by
> content. Print. Restore old document.

Race condition, bad idea.

> In jQuery, see »printElement«.

Worst idea so far, cracking a nut with a hand grenade (*iff* it goes off).

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.

Mike Scirocco

4/8/2016 6:46:00 AM

0

On 4/6/2016 2:41 AM, Teodor V. wrote:
> On 2016-04-06 09:00, Mike S wrote:
>> On 4/5/2016 7:33 PM, Stefan Ram wrote:
>>> Mike S <mscir@yahoo.com> writes:
>>>> Iow can I ignore everything but the content I
>>>> want to print and use html tags to formate it, like maybe just
>>>> formatting the content in a new div and printing that?
>>>
>>> Yes. Copy the content to a new window. »w = window.open ...«,
>>> »w.write( contents )«, »w.print ...«.
>>>
>>> If you have a popup-blocker: Use a custom css for printing,
>>> which will hide everything but the content.
>>>
>>> Or: Save the old document in a variable. Replace document by
>>> content. Print. Restore old document.
>>>
>>> In jQuery, see »printElement«.
>>>
>> printElement looks good.
>>
>> http://www.bennadel.com/blog/1591-ask-ben-print-part-of-a-web-page-with-...
>
> FWIW, the CSS approach is the most compatible for users who fly with
> Javascript disabled.
> I use it the pages I design, minimal CSS and formatting, just enough to
> produce a clean printout.
>
> /Teo.

Thanks /Teo