...

View Full Version : onbeforeprint handler



havey
09-26-2003, 09:17 PM
How would I use the onbeforeprint handler to dynamically populate the link tag to print the correct .txt file(href="printerfriendly.txt") from a called JS function?"

I forgot to mention what a link tag is for those who are not sure:

<link rel="alternate" media="print" href="printerfriendly.txt">

the printerfriendly.txt needs to be populated with
start.txt when the start function is involked, simularily
text1.txt when text1 function is involked;
page2.txt with page2 function; AND
ender.txt with ender function

hope this makes sense!


hmm... I'm lost making the association between the JS functions (that are going to be called) to set the href of the link tag?

<head>

<link rel="alternate" media="print" href="printerfriendly.txt">

<script language="JavaScript"><!--
function text1(){


}
function text2(){


}
function text3(){


}
// --></script>
</head>

<body onbeforeprint="text1();text2();text3();">

Actual page here

</body>

havey
09-26-2003, 09:58 PM
I've played around with it and this is what I came up with, which doen't work, please help.

<head>

<script language="JavaScript"><!--
function text1(){
document.writeln("<link rel="alternate" media="print" href="text1.txt">");
}
function text2(){
document.writeln("<link rel="alternate" media="print" href="text2.txt">");
}
function text3(){
document.writeln("<link rel="alternate" media="print" href="text3.txt">");
}
// --></script>
</head>

<body onbeforeprint="text1();text2();text3();">

Lazaroth
09-27-2003, 12:15 AM
A note:

You can't have the same type of tag without using \ before it.

Ie.

document.writeln('<link rel="alternate" media="print" href="text1.txt">');

or

document.writeln("<link rel=\"alternate\" media=\"print\" href=\"text1.txt\">");



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum