/    Sign up×
Community /Pin to ProfileBookmark

Print Function

Hi, I am trying to create a print function. I am using frames and I have the print button in the top frame or contents frame. I have the text document in the detail frame. I wish to use the print button in the content frame to print whatever text document that shows up in the detail frame. I am a novice and need a little help, here is what I have so far.
[COLOR=darkblue]
<body>

<SCRIPT LANGUAGE=”JavaScript”>

<!– Begin
if (frame.print) {
document.write(‘<form>’
+ ‘<input type=button name=print value=”Print” ‘
+ ‘onClick=”javascript:frame.print(Detail)”> </form>’);
}
// End –>
</script>

</body></html>
[/COLOR]
Thanks in advance for any help.
Mike

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@ShampieOct 26.2003 — javascript:this.parent.frame.print();

remove the space between java and script.
Copy linkTweet thisAlerts:
@mike1authorOct 26.2003 — Hi, thank you for your response but I guess in the copy paste function that space appeared but my actual script does not have that space. I still get an error, 'frame' undefined. I confess I do not know the whole JS language. How do I get a page to print in another frame?

Txs Mike
Copy linkTweet thisAlerts:
@ShampieOct 26.2003 — can you copy and paste your full page in here (the framepage)?
Copy linkTweet thisAlerts:
@mike1authorOct 26.2003 — I was only playing with either of the two html pages, the contents and the details. Do you think the answer lies in the frame page?

Here it is...


<html>

<head>

<title>This page contains frames.</title>

</head>

<frameset rows="1*, 1*">

<frame src="noname2.htm" name="Contents">

<frame src="noname1.htm" name="Detail">

<noframes>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">

<p>This page contains frames. You need a Web browser that supports frames

to view this page correctly.</p>

</body>

</noframes>

</frameset>

</html>

I have kept my project very basic until it works, then I will build it up.

Txs again, Mike
Copy linkTweet thisAlerts:
@ShampieOct 26.2003 — <frame src="noname2.htm" name="[COLOR=red]Contents[/COLOR]">


the red part will be the frame name which should be used instead of frame:

javascript:this.parent.frame.print();


will be:

javascript:this.parent.[COLOR=red]Contents[/COLOR].print();

this will print noname2.htm.

if you want noname1.htm then change 'Contents' to 'Detail' altough I did not test if it will actually only print that frame or the whole page.
Copy linkTweet thisAlerts:
@mike1authorOct 26.2003 — Hi Shampie, I am getting an error 'null or this is not an object'. Where do I put my code? In the button frame? In the detail frame or in the main html frame?

One other note,

if (frame.print) {

Does this line also change to:

if (this.parent.Contents.print) {

Txs Mike
Copy linkTweet thisAlerts:
@ShampieOct 26.2003 — put a button on the noname2.htm or noname1.htm page (not on the frame page)

<input type="button" name="Button" value="Print" onClick="printer();">


then add this on the same page in the body part

[code=php]
<script>
function printer(){
alert("Now printing...");
// use 1 of the following 3 (or if you want to print all pages use all)
this.parent.print(); // this will print current page.
parent.Contents.print(); // print Content page.
parent.Detail.print(); // print Detal page.
}</script>[/code]
Copy linkTweet thisAlerts:
@mike1authorOct 26.2003 — Hi Shampie, I really appreciate you trying to help me, thanks again. I still don't seem to be able to get the result I am looking for. I like the snippet you wrote because it is so simple but this is the third attempt of trying to get this right. The code seems to work well for just printing the existing page but not another page in a frame set. I took another stab at it and tried to define an object but I still cannot get the code to work the way I need. Here is your one line of code and the new one I was trying with the defined object. Any ideas?

...new try

[COLOR=darkblue]

<head>

<SCRIPT LANGUAGE="JavaScript">



<!-- Begin

function printer(text){

text=detail

print(text)

}

// End -->



</script>

</head>

[/COLOR]


...your script

[COLOR=darkblue]

<body>



<script>
function printer(){parent.Detail.print();}
</script>

[/COLOR]

Txs Mike
Copy linkTweet thisAlerts:
@ShampieOct 27.2003 — Reminder to javascript is case-sensitive in the way that you used detail and Detail.

Your frame name is Detail not detail, try to see if that helps.

what you else might want to do (if you only want to print one of the frame is to put a link that when you click that link it opens a window with the frame page and it will print the page when the page is loaded.

use window.open to open the frame page..

<body onLoad="javascript:this.parent.print()">

one problem you have to work around is that if you use the frame page that contains the <body onLoad="javascript:this.parent.print()"> code will also run when you use it on your normal page. (suggesting using a Detaila (almost same as Detailb) but without the <body onLoad="javascript:this.parent.print()"> code in it.

Detailb is same as a but with <body onLoad="javascript:this.parent.print()"> code in it.

if you already have a body code just add this tag into it: onLoad="javascript:this.parent.print()"
×

Success!

Help @mike1 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...