/    Sign up×
Community /Pin to ProfileBookmark

javascript: onClick=’print();’

I use a onClick=’print();’ inside a link. It does not work. I use it in a popup window that does not have any foreward, back… buttons. Im wondering if that is the problem. Here is the code, sorry its a mess, but it is generated so the formatting is none ?

[code]
<h1>Graded Results</h1><h3>For: sdfdfs Date: sdfsdf</h3><a href=’#’ onClick=’print();’>Print This</a><br>0/4 <b>0%</b><br><br><b>1. Wrong. What is your name:<br></b><b>Jeff</b><br>You put:<br>sdffsd<br><br><b>2. Wrong. What gender:<br></b><b>Male</b><br>You put:<br>sdfdfs<br><br><b>3. Wrong. What do you ride:<br></b><b>I have a car</b><br>You put:<br>sdfdfs<br><br><b>4. Wrong. What is favorite color:<br></b><b>black</b><br>You put:<br>sdfsdf<br><br>[/code]

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@David_HarrisonJun 07.2004 — window.print()

And use document.writeln instead.
Copy linkTweet thisAlerts:
@rex64authorJun 07.2004 — I want to print the HTML document just the way it looks. I do not want to print the code or anything. I just want to send the HTML document that they are viewing on the screen straight to the printer.
Copy linkTweet thisAlerts:
@David_HarrisonJun 07.2004 — So window.print() then.

And as a separate point, use document.writeln to create your pop-up code.
Copy linkTweet thisAlerts:
@rex64authorJun 07.2004 — window.print() does not work in a popup window. I already tried it.
Copy linkTweet thisAlerts:
@David_HarrisonJun 07.2004 — Can you post you pop-up generating code please.
Copy linkTweet thisAlerts:
@rex64authorJun 07.2004 — It is very lengthy. But here are some pieces:

[code=php]
function newWindow()
{
//var popurl="weatherPop1.html"
winpops=window.open("_blank","","width=650,height=490,")
}

function writeToWin(theString)
{
getObject(winpops).document.write(theString);
}

writeToWin("<a href='#' onClick='print();'>Print This</a><br>");
[/code]
Copy linkTweet thisAlerts:
@David_HarrisonJun 07.2004 — I've simplified the code, although why do I get the feeling that you call your writing function over and over again.var winpops;

function combined(theString){

//var popurl="weatherPop1.html"

winpops=window.open("","newwin","width=650,height=490");

winpops.document.writeln('&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"');
winpops.document.writeln(' "http://www.w3.org/TR/html4/loose.dtd"&gt;');
winpops.document.writeln('&lt;html lang="en"&gt;');
winpops.document.writeln('&lt;head&gt;');
winpops.document.writeln('&lt;title&gt;'+alternateText+'&lt;/title&gt;');
winpops.document.writeln('&lt;meta http-equiv="content-script-type" content="text/javascript"&gt;');
winpops.document.writeln('&lt;meta http-equiv="content-style-type" content="text/css"&gt;');
winpops.document.writeln('&lt;meta http-equiv="content-type" content="text/html;charset=iso-8859-1"&gt;');
winpops.document.writeln('&lt;/head&gt;');
winpops.document.writeln('&lt;body&gt;');

winpops.document.writeln(theString);

winpops.document.writeln('&lt;/body&gt;');
winpops.document.writeln('&lt;/html&gt;');
winpops.document.close();

}

combined("&lt;p&gt;&lt;a href='#' onclick='print();'&gt;Print This&lt;/a&gt;&lt;/p&gt;");
The print button wasn't working because you didn't close the document once you'd finished writing to it. A common mistake that many people make.
Copy linkTweet thisAlerts:
@rex64authorJun 07.2004 — Your amazing. All I had to do was close the document. Thanks.
Copy linkTweet thisAlerts:
@David_HarrisonJun 07.2004 — Happy to help. ?
Copy linkTweet thisAlerts:
@heenathkJul 18.2007 — Hello

window.print() does not work in a popup window, i tryed it,but i couldn't



window.print() does not work in a popup window. I already tried it.[/QUOTE]
Copy linkTweet thisAlerts:
@felgallJul 18.2007 — Hello

window.print() does not work in a popup window, i tryed it,but i couldn't[/QUOTE]


Read the code in this thread for how to get it to work. It does work in ANY web page provided you code it right.
×

Success!

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