搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

Learn More

window.print() does not work in firefox 12 version where as the same works in IE

  • 1 回覆
  • 4 有這個問題
  • 5 次檢視
  • 最近回覆由 cor-el

more options

The following is the extract of page source of my application:

<script language='javascript'>
			function fncPrint()
			{
				document.getElementById("btnPrint").style.visibility="hidden";
				document.getElementById("btnClose").style.visibility="hidden";
				window.print();
				document.getElementById("btnPrint").style.visibility="visible";
				document.getElementById("btnClose").style.visibility="visible";
			}
</script>


<td align='center' colspan='10'>
	<input type='button' class='button' value='Print' name='btnPrint' onclick='fncPrint()'>
	<input type='button' class='button' value='Close' name='btnClose' onclick='window.close()'>
</td>

This code works fine IE but when used with firefox does nothing, it does not go for printing. I can use Control+P but it will not dim print and close buttons.

The following is the extract of page source of my application:<br /> <br /> <pre><nowiki><script language='javascript'> function fncPrint() { document.getElementById("btnPrint").style.visibility="hidden"; document.getElementById("btnClose").style.visibility="hidden"; window.print(); document.getElementById("btnPrint").style.visibility="visible"; document.getElementById("btnClose").style.visibility="visible"; } </script> <td align='center' colspan='10'> <input type='button' class='button' value='Print' name='btnPrint' onclick='fncPrint()'> <input type='button' class='button' value='Close' name='btnClose' onclick='window.close()'> </td> </nowiki></pre> This code works fine IE but when used with firefox does nothing, it does not go for printing. I can use Control+P but it will not dim print and close buttons.

由 cor-el 於 修改

被選擇的解決方法

You use document.getElementById("btnPrint"), but you only specify the NAME attribute in the input tags and not the ID.
So you will have to add the ID as well to make Firefox find that element.

<input type='button' class='button' value='Print' id='btnPrint' name='btnPrint' onclick='fncPrint()'>
<input type='button' class='button' value='Close' id='btnClose' name='btnClose' onclick='window.close()'>
從原來的回覆中察看解決方案 👍 1

所有回覆 (1)

more options

選擇的解決方法

You use document.getElementById("btnPrint"), but you only specify the NAME attribute in the input tags and not the ID.
So you will have to add the ID as well to make Firefox find that element.

<input type='button' class='button' value='Print' id='btnPrint' name='btnPrint' onclick='fncPrint()'>
<input type='button' class='button' value='Close' id='btnClose' name='btnClose' onclick='window.close()'>