/    Sign up×
Community /Pin to ProfileBookmark

Print content from a div?

I got the content to pop up into a new window, based on which button I chose, and then the pop-up window opens and just prints. Pretty ugly, for it to just pull up a new window just to print.

Is there a way for me to print a specific div, based off of the current code that I have?

[B][U]MainPage[/U][/B]

[code=html]
<html>
<head>
<script type=”text/javascript”>
var contentHTML = “Couldn’t find Content”;
function popup(obj) {
var contentName = obj.parentNode.childNodes;
for (var i=5; i<contentName.length; i++) {
if (contentName[i].tagName != undefined) {
contentHTML = contentName[i].innerHTML;
break;
}
}
var winPopup = window.open(‘content.html’,”,’width=410,height=400,toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no’);
}
</script>
</head>

<body>
<div>
<div>content1</div>
<input type=”button” value=” print content1 ” onclick=”popup(this)”>
</div>
<br />
<br />
<div>
<div>content2</div>
<input type=”button” value=” print content2 ” onclick=”popup(this)”>
</div>
</body>
</html>
[/code]

[B][U]Pop-Up Page[/U][/B]

[code=html]<script type=”text/javascript” language=”JavaScript”>
function showIt() {
document.getElementById(‘coupon’).innerHTML = window.opener.couponHTML;
window.print();
}

</script>[/code]

So basically now I just want if this or that button is click that it print that specific div and not the entire page.

So if anyone can help, big thanks in advance.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Feb 13.2008 — Look into CSS Print Media where you can set up a stylesheet to hide everything but the stuff you want to print out.

Eric
×

Success!

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