1

I am trying to open a print dialog box in Opera browser using javascript code as

<script language=javascript>
window.print(); //This is working in IE, Netscape, Firefox, but not working in Opera
</script>

where as if I am using the following code Opera browser understands and able to open print dialog box

<input type="button" value="Print this page" onClick="javascript:window.print();" ID="Button1" NAME="Button1">

My requirement is to open print dialog box in Opera browser using script block. Can anyone help me?

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
Aadi
  • 6,959
  • 28
  • 100
  • 145
  • See this link, hope it will help you. [http://stackoverflow.com/questions/2555697/window-print-not-working-in-ie][1] [1]: http://stackoverflow.com/questions/2555697/window-print-not-working-in-ie – PythonDev Mar 15 '12 at 08:00
  • Please check my answer on this similar issue: http://stackoverflow.com/questions/4582767/print-not-working-on-opera-browser/8220731#8220731 – Jean G.T May 16 '12 at 21:12

2 Answers2

2

Try putting your code in load event:

<script language=javascript>
window.onload = function(){
  window.print();
};
</script>
Sarfraz
  • 377,238
  • 77
  • 533
  • 578
0

You need to make sure the whole web page is loaded in Opera before you call window.print();

So using this may help - not, I am waiting for the page to load AND causing a slight delay, which is a little known fix for some versions of Opera.

Hope it helps.

window.onload = function () {
    window.setTimeout(function () {
        window.print();
    }, 500);
}
Fenton
  • 241,084
  • 71
  • 387
  • 401
  • Thank you for all of your contribution.very much sorry to inform that these are not working with opera(but woks in other browsers) – Aadi Aug 14 '10 at 07:39
  • What version of Opera are you using - this works in 10.61. Can you post an example of your page, in case these is some other issue, such as you are adding two onload event handlers. – Fenton Aug 15 '10 at 21:21