/    Sign up×
Community /Pin to ProfileBookmark

Curious Problem With print()

Hi All,

The problem is a curious one.
This works…
<a href=’javascript: print()’> (take the space out… leaving it in causes substitution with this stupid :p)

This doesn’t…
<script language=’javascript’>
print();
</script>
</body>

I’m trying to get a point of sale system to print the receipt, but first it has to send the shopping cart to a php script to record the transaction and then return the transaction number (which is then included on the receipt).

If the user clicks the link that contains the print function, it will print, but it hasn’t sent the data to php to perform the transaction update.

If the link instead sends the data to php, and then the target page calls print() at the end of the page load, it doesn’t work.

Any suggestions?

Thanks
CTB

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@NatdripDec 02.2005 — I have a few have the function fired off after the php return.

use the php to call it. at the end of php import caller.

When the page opens open right before the information is sent have js open a controller page. the controller page then opens starts pinging the php exe. have the php exe close and another and the pinging function to do something if page not present.

use setTimeout("function()", 500)

I am sorry I have been on a project 32 hours straight. the logic is here i think. i'd give php examples but I don't use PHP sry ASP JSP(im a nub) only ?
Copy linkTweet thisAlerts:
@chestertbauthorDec 03.2005 — Thanks for trying to assist Nadrip. I think I figured out the logic of your reply... you really need to get more sleep buddy... and it's similar to the way the thing was written in the first place.

It seems, however, that the problem wasn't with print() at all but with the W3C document type.

My document header used to be...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

When I removed the !doctype definition, print() suddenly worked as required.

I guess that's what happens when bureaucrats get involved and try to force you to define things that fit within their little view of the world (though I'm sure there are many here who would fight to defend them, and can give me all manner of persuasive reasons why collectivelty wasting days of your time and mine trying figure this out was 'necessary').

CTB
Copy linkTweet thisAlerts:
@FromU2MEDec 04.2005 — Try this: [B]<body onload="window.print()">[/B]

With that code it doesn't really matter what headers you have! Never rely on

<script language="javascript">

print();

</script>
Copy linkTweet thisAlerts:
@chestertbauthorDec 04.2005 — Thanks FromU2ME.

Tried that variation too. With the header... didn't work... without the doc type header... worked.

The problem really is a curiosity.

I actually think it has to do with timing and the inner workings of browsers. I suspect that with the doc type header, the browser has a little more work to do before it draws the page because I fixed it for both as follows;

In the header...

<script language='javascript'>

function printit()

{

setTimeout("print()",500); //in the doc type version, the timeout needed to be 1500

submitit();

}

function submitit()

{

setTimeout("document.getElementById('process').submit()",4000); //or 100000 in doc type version

}

</script>

And in the body...

<body onLoad='javascript: printit()'>

Thanks for the assistance.

CTB
×

Success!

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