473,324 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

javascript beforeprint not working in mozila

77
hello all. i have html page to be printed out..it's generated by the button print like below

<input type="button" name="btn_print" value="Print Invoice" onClick="javascript:window.print();">

of course, the button will shown to the page when it's printed..
but i don't want that button shown when user print the page (paper) or when the user commands "print preview" in the browser...

Than, i already solve the request with this function below..

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. // Hide tags with id="noprint" when printing
  3. function DoNotPrint()
  4.     {
  5.         var a = document.all.item("noprint");
  6.       if (a!=null) {
  7.             if (a.length!=null) {
  8.             //multiple tags found
  9.                 for (i=0; i < a.length; i++) {
  10.                 a(i).style.display = window.event.type == "beforeprint" ? "none" :"inline";
  11.             }
  12.         } else 
  13.         //only one tag
  14.         a.style.display = window.event.type == "beforeprint" ? "none" :"inline";
  15.     }
  16. }
  17. </script>
and the body HTML is like below :

<body onafterprint="javascript:DoNotPrint();"onbeforepri nt="javascript:DoNotPrint();">

so, when user commands print preview or print the page, the button "btn_print" above, will not shown..

the problem is, that's works only in IE, doesn't work in mozilla...

so, any idea???

thanks before

regards, maminx
Dec 3 '08 #1
4 3452
maminx
77
sorry forgot the HTML code rules..here i repost my question

hello all. i have html page to be printed out..it's generated by the button print like below

[HTML]<input type="button" name="btn_print" value="Print Invoice" onClick="javascript:window.print();">[/HTML]

of course, the button will shown to the page when it's printed..
but i don't want that button shown when user print the page (paper) or when the user commands "print preview" in the browser...

Than, i already solve the request with this function below..

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. // Hide tags with id="noprint" when printing
  3. function DoNotPrint()
  4.     {
  5.         var a = document.all.item("noprint");
  6.       if (a!=null) {
  7.             if (a.length!=null) {
  8.             //multiple tags found
  9.                 for (i=0; i < a.length; i++) {
  10.                 a(i).style.display = window.event.type == "beforeprint" ? "none" :"inline";
  11.             }
  12.         } else 
  13.         //only one tag
  14.         a.style.display = window.event.type == "beforeprint" ? "none" :"inline";
  15.     }
  16. }
  17. </script>
and the body HTML is like below :

[HTML]<body onafterprint="javascript:DoNotPrint();"onbeforepri nt="javascript:DoNotPrint();">[/HTML]

so, when user commands print preview or print the page, the button "btn_print" above, will not shown..

the problem is, that's works only in IE, doesn't work in mozilla...

so, any idea???

thanks before

regards, maminx
Dec 3 '08 #2
acoder
16,027 Expert Mod 8TB
Instead of using JavaScript, use a print stylesheet to hide the button. See Going to print.
Dec 3 '08 #3
maminx
77
i've already solve the problem.
Dec 16 '08 #4
acoder
16,027 Expert Mod 8TB
That's good to see. For something like this, CSS is the way to go.
Dec 16 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: nmueggler | last post by:
Hi I'm working on a Word 2003 mail merge component for a windows client. My problem is that the BeforePrint Event ist not raised if the user is printing directly out of word, but if I'm running...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
2
by: imingsutantotan | last post by:
Hi, this code below is working on IE 6 and 7 but not mozila firefox. i do not know why I have reviewed the code for 3 times. please help me. regards, Iming <div id="slideShowData"...
1
by: shyamg | last post by:
hi any body can give best link for javascript validation textfields numric and alpha numric validation ...its working in mozila ... thanks. ss
4
by: Nuno | last post by:
Hello, I'm trying to call some web services only using javascript from a html page. I succeeded on doind this in IE with the use of the behavior:url(webservice.htc); (technique founded in the...
2
by: shivendravikramsingh | last post by:
hi friend,i have a problem in my page,when i open my page a error msg display "javascript error out of stack space",but same page i open in opera or mozila its work fine.but in I.E i got this msg,and...
1
by: venkatesham143 | last post by:
UploadImage.jsp :- <body> <form name="UploadImage" method="post" action="UploadImageServlet" > Building Image: <INPUT type="file" Size="33" contentEditable="false" name=image...
3
by: sarika | last post by:
Hi all I m making a website in which i have used ajax technology . When i make a page request throght ajax it works fine in IE but giving problems in Mozilla .In mozila i m getting 403 status code...
3
oranoos3000
by: oranoos3000 | last post by:
hi i d like to create a table of safe color for web as online. i show a table of safe color on the page and i want to by clicking user on the links background-color document is changed but sorry...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.