I have a Rails 3.2 site and am using a javascript print routine that has suddenly stopped working. Here's my print routine code:
function print() {
var mywin = window.open('', '', '');
mywin.document.write('<body><link href="/assets/application.css" media="all" rel="stylesheet" type="text/css" />' + document.getElementsByClassName('fields')[0].innerHTML + '</body>');
mywin.print();
mywin.close();
return false;
}
Code has been running fine for months, but now whenever you try to print it just prints two blank pages. It throws an error on the second line, cannot read property 'document' of undefined, and inspection reveals that mywin is undefined.
Googling didn't yield any worthwhile results, so anyone have any clue why this is happening?
I had the same problem in a non-rails environment. I am using node's http-server, working on localhost.
The trouble was that Chrome was automatically blocking pop-ups from localhost. I went to the settings and added "localhost" as an exception, and now everything works great!
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With