catchup
09-25-2003, 03:32 PM
Is there any way that i can redirect the user to another page when the browser print button is pressed on IE browser?
|
Click to See Complete Forum and Search --> : print button catchup 09-25-2003, 03:32 PM Is there any way that i can redirect the user to another page when the browser print button is pressed on IE browser? requestcode 09-26-2003, 07:14 AM No. Javascript does not have the ability to detect that. Charles 09-26-2003, 07:18 AM You can, however use the LINK (http://www.w3.org/TR/html4/struct/links.html#edef-LINK) element to specify an alternative version of the document or an alternative style sheet to be used when printing. I hven't had much luck with the former but the later is much fun. Especially as you can use CSS to keep things from being displayed. pyro 09-26-2003, 07:29 AM Actually, the answer to your question is "Yes", as you asked about the IE browser. Take a look at the onbeforeprint (http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/events/onbeforeprint.asp) and onafterprint (http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/events/onafterprint.asp) event handlers. Do remember, however, that it is proprietary IE code, and as such will most likely not work in other browsers and that must be taken into consideration. requestcode 09-26-2003, 10:08 AM Boy I goofed on that one. Thanks Charles and Pyro for pointing that out. catchup 09-26-2003, 10:20 AM Thanks Pyro! I'm trying to use CSS with the onbeforeprint handler. I'm calling one of the JS funtions (text1,2&3) to print the respective text via the IE browser print button. This is what I have / am struggling with, so far, How do I call text1.html to print from the browser print button? <head> <style type="text/css"> #print_text1 { display:none; } @media print { #print_invisible { display:none; } #print_text1 { display:block; } } #print_text2 { display:none; } @media print { #print_invisible { display:none; } #print_text2 { display:block; } } #print_text3 { display:none; } @media print { #print_invisible { display:none; } #print_text3 { display:block; } } </style> <script language="JavaScript"><!-- function text1(){ .....// how do i call text1.html to print function text2(){ .... } function text3(){ .... } // --></script> </head> <body onbeforeprint="text1();text2();text3();"> <span id="href='text1.html'"> Actual page here </span> <span id="href='text2.html'"> Actual page here again </span> <span id="href='text3.html'"> Actual page here again </span> </body> pyro 09-26-2003, 10:37 AM By the looks of what you need there, you should look into the method the Charles explained, as it will work cross-browser. A good article on that can be found at http://www.alistapart.com/stories/goingtoprint/ catchup 09-26-2003, 11:20 AM Pyro, Thanks! I wish I could strip down the page like i the A List Apart example but in my situation I using a flash file that has buttons which calls another swf into the original swf, to display a scroller containg text. I have a printer friendly buttons in the swfs that prints external .txt files, which is the same text that each scroller contains. I'm trying to make thing more user frienld by incorporating the IE browser print button into the senerio. Because I have an external .txt file for each piece of text in each scroller, and because I want to target each .txt file to print via the browser button, I thought maybe when a JS function is initiated from inside Flash, I could somehow use the onbeforeprint handler to select the appropiate .txt file to print, depending on which JS was initiated from inside the swf. Now with that all said.... what's your take on this? pyro 09-26-2003, 12:40 PM Sounds like maybe this will help: http://www.dynamicdrive.com/dynamicindex9/printstyle.htm. Basically, you are just using the <link> tag (as Charles said) to spedify which document to be printed. <link rel="alternate" media="print" href="printerfriendly.txt"> catchup 09-26-2003, 02:29 PM I see... My thoughts are fuzzy on this... I have 15 buttons each open a swf with a text scroller, so i have to initiate a JS function in the html from flash to populate the link tag with the correct .txt file to print, so the browser print button prints what is displayed in the swf scroller. So 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? 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> catchup 09-26-2003, 03:30 PM i think I go some going but it doesn't quite 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();"> webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |