printing an iframe...worked in 0.9.7, not in 0.9.8

26 views
Skip to first unread message

sc...@collobos.com

unread,
Apr 26, 2015, 11:37:07 PM4/26/15
to objec...@googlegroups.com
Hey folks.  I recently upgraded my Capp environment to 0.9.8 and my app pretty much still works except for one thing.  I have a place in my code where I create an hidden iframe on the fly with the intention of printing it.  This worked perfectly in 0.9.7 but not in 0.9.8.  Unfortunately, my HTML/CSS skills are meager at best (which is why I love Capp) and I have little idea what might have caused this to break.

The code is simple:

---- CUT HERE -----

var iframe = document.createElement( 'iframe' );
iframe.style.display = 'none';
iframe.src = [ CPString stringWithFormat:@"/qr?action=print&oid=%@", [ [ self representedObject ] oid ] ];
iframe.onload = function()
{
iframe.focus();
iframe.contentWindow.print();
iframe.parentNode.removeChild( iframe );
};
document.body.appendChild( iframe );

---- CUT HERE -----


Like I said, worked in 0.9.7, not in 0.9.8.  Not sure I understand how a Capp version change could have affected this, as it's not strictly Capp code.

Any help would be greatly appreciated.

Thanks,

Scott

daboe01

unread,
Apr 27, 2015, 12:00:55 AM4/27/15
to objec...@googlegroups.com
hi scott,
try your app in different browsers with both 0.9.7 and 0.9.8 to find out whether this is really related to the capp update.
are there messages in the console?
best greetings,
daniel

sc...@collobos.com

unread,
Apr 27, 2015, 1:00:14 PM4/27/15
to objec...@googlegroups.com
Hey Daniel!  I found out what the problem is, but still am unclear whether it's related to the Capp upgrade.

iframe.focus();
iframe.contentWindow.print();
iframe.parentNode.removeChild( iframe );

The third line is what caused the problem.  Not sure why this wasn't happening in 0.9.7, but if I call removeChild() right after calling print() it doesn't seem to let the printing framework do it's job.  If I comment that line out, everything works as it used to.

No console output at all when it doesn't work by the way.  

I'll just work around this by only creating one hidden iframe instead of creating one every time I go to print.  Very strange...but a happy ending nonetheless.

Thanks,

Scott
Reply all
Reply to author
Forward
0 new messages