/    Sign up×
Community /Pin to ProfileBookmark

I have a webpage that has a ‘Print page’ link on it with the following code:

<a href=”javascript:window.print()” title=”Print Page”>Print Page</a>

Which works fine but it prints everything on the page. Can anyone give me the code where it just prints the content without the images?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 22.2005 — print() does nothing more than open the PRINT window of your browser.

But you may use CSS to formatting the printing. See:

http://www.w3.org/TR/REC-CSS2/page.html

Even so, I am not sure that you may ommit images from printing.

Usually, webdesigners build a second so called "print page" (most of the time via a server-side application, but it can be done with javascript as well, even I am not sure it worths the effort)

If u need this to protect some pictures, I assure you that the only secure way is to watermark them.
Copy linkTweet thisAlerts:
@BrainDonorJul 22.2005 — Something like this?

<html>

<head>

<style type="text/css" media="print">

.pic {display: none; }

</style>

</head>

<body>

Here is some text

<br>

<a onclick="window.print();return false" href="#">Print Page</a>

<br>

<img class="pic" src="http://www.google.com/intl/en/images/logo.gif">

</body>

</html>
Copy linkTweet thisAlerts:
@Jonny_LangJul 22.2005 — Main document has Normal and Printable view buttons to swap style sheets.

Main document:

[CODE]<HTML>
<Head>
<LINK href='Normal.css' rel=stylesheet>
<LINK href='Printable.css' rel=stylesheet>
<style media="print" type="text/css">#normBtn {display:none}</style>
<style media="print" type="text/css">#prnBtn {display:none}</style>
<Script Language=JavaScript>

function normalView(){

document.styleSheets[0].disabled = false;
document.styleSheets[1].disabled = true;
document.getElementById('normBtn').disabled = true;
document.getElementById('prnBtn').disabled = false;
}

function printView(){

document.styleSheets[0].disabled = true;
document.styleSheets[1].disabled = false;
document.getElementById('normBtn').disabled = false;
document.getElementById('prnBtn').disabled = true;
}

window.onload=normalView;

</Script>
</Head>
<Body>
<H2 id='someHeadline'> This is an H2 Headline </H2>
<p id='someText'> This is a paragraph of text </p><br>
<Img Src='1/Any.jpg' id='someImg'>
<hr>
<center>
<input type=button value="Normal View" id='normBtn' onClick="normalView()">&nbsp;&nbsp
<input type=button value="Printable View" id='prnBtn' onClick="printView()">
</center>
</Body>
</HTML>[/CODE]


Normal.css:

[CODE]Body {background-color: lightsteelblue;}

H2 {font-size: 24pt; color: blue;}

p {font-family: tahoma; font-size: 14pt;}

IMG {display: inline;}

HR {display: inline;}[/CODE]



Printable.css:

[CODE]Body {background-color: white;}

H2 {font-size: 14pt; color: black;}

p {font-family: ariel; font-size: 12pt;}

IMG {display: none;}

HR {display: none;}[/CODE]
×

Success!

Help @emma 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,
)...