/    Sign up×
Community /Pin to ProfileBookmark

document.print()

hi all,
I tried to use the below function to print my webform written in asp.net when I click the “print” button. But a statment “error on page appears” in the status bar in IE. Does anyone know what is the problem?(Note: it goes fine when I use window.print()?
<script LANGUAGE=”JavaScript”>
function printWindow() {
document.print();
}
</script>

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@Zach_ElfersDec 30.2002 — Use "document.write();" instead.
Copy linkTweet thisAlerts:
@im_wclaaauthorDec 30.2002 — hi,

I have tried but when I click the button. The page is not printed out. The page just "hanged" instead. Thx.
Copy linkTweet thisAlerts:
@Zach_ElfersDec 30.2002 — OOPS!!! I wasn't even thinking right. It's 3:30 a.m. where I am and I told you document.write();. I am so stupid. documen.write() is used to put text on a page.
Copy linkTweet thisAlerts:
@im_wclaaauthorDec 30.2002 — hi,

It's fine and still thx ur effort. But do u have any other ideas?
Copy linkTweet thisAlerts:
@Zach_ElfersDec 30.2002 — Maybe:

this.document.print();

???
Copy linkTweet thisAlerts:
@im_wclaaauthorDec 30.2002 — hi,

It is still not ok. I dont know why. I wanna ask if u have used document.print() before? Does it works?

Actually, why I use it becoz I wanna print the form without showing the scroll. Do u have any other suggestion to do that?

Thx.
Copy linkTweet thisAlerts:
@CharlesDec 30.2002 — [font=georgia]It's [font=monospace]window.print[/font] and not [font=monospace]document.print[/font] and it only works in MIcrosoft and then only when the user has not disabled scripting. To avoid a link to nowhere use JavaScript to draw the link only when it will work:[/font]

[font=monospace]

<script type="text/javascript">

<!--

if (window.print) {

document.write('<a href="#">Print this page.</a>');

document.links[document.links.length-1].onclick = function () {window.print(); return false};

};

// -->

</script>

[/font]
×

Success!

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