Print button with ASP or JavaScript

Results 1 to 4 of 4

Thread: Print button with ASP or JavaScript

  1. #1
    Ryne Guest

    Default Print button with ASP or JavaScript

    I have to make a button or link where user can click and it will automatically print the window/frame content without showing print dialog box first. The result should be in landscape orientation. Is it possible to make it with ASP or I have to use Java Script? <BR>Please help me with this, both ASP or JavaScript! Or at least links to any articles about this. <BR>Thanx ....<BR>

  2. #2
    Tobias Andersen Guest

    Default RE: Print button with ASP or JavaScript

    Hallo there friend...ill help you with that one in a flash...:)<BR><BR>JavaScript would be the correct solution for this method of might ask why and its pretty simple....ASP is server side scripting, while JavaScript is client side scripting. and the object you need to activate is build into the browser, so you have all you need on the client so why make an annoying detour to the server for this...:)<BR><BR>Just paste the below code into your script section in the header and that should do it:<BR>&#060;!--<BR> var myWindow = "";<BR> var NS = (navigator.appName == "Netscape");<BR> var VERSION = parseInt(navigator.appVersion);<BR><BR> function printit(){<BR> if (NS) {<BR> window.print() ; <BR> } else {<BR> var WebBrowser = &#039&#060;OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"&#062;&#060;/OBJECT&#062;&#039;<BR> document.body.insertAdjacentHTML(&#039beforeEnd&#0 39, WebBrowser);<BR> WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = "";<BR> }<BR> }<BR>--&#062;<BR><BR>there is a know bug in the script, if you cancel a print command in the print dialog box, the script wil return a javascript error...but add this code, also within the javascript tag in the head, and you will suppres errors...<BR><BR>self.onerror = function(){ return true; }<BR><BR>Sencerly<BR>Tobias Andersen<BR>

  3. #3
    Ryne Guest

    Default RE: Print button with ASP or JavaScript

    Wow ... I&#039m really not good in JavaScript, the code is quite confusing for me. But it works, thanx a lot ..<BR>BTW, can we change the print properties by coding so we don&#039t have to view print dialog box and still can get the setting like we want (in my case the print result should be in lanscape orientation)?

  4. #4
    Ryne Guest

    Default RE: Print button ... to Tobias Andersen

    Sorry ... have just realized that the error trapping code is not working and it still showing error message. I need your guide, where do I have to put that error trapping code?<BR>For your information, here is the link I made in the HTML page body :<BR>&#060;a href="javascript:printIt()"&#062;Print&#060;/a&#062;<BR>I use a link instead of button for my own consideration.<BR>Thanx a lot ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts