var s="browser print test 2 - IFrame"
//keep in mind an iframe needs it's own css
//grab the table element
var $table = $('#wallTable');
//create the iframe in order to target it
var $iframe = $('<iframe>')
.attr('id','printView');
//append iframe
$('#con').append($iframe);
//get the document of iframe
var doc = $('#printView').get(0).contentWindow.document;
var printBody = $('body', doc);
var printHead = $('head', doc);
printBody.addClass("custBody");
//create your own style css - Not in use
//var $link = $("<style>");
//$link.append('#wallTabl img {border: thin solid //red;}');
//transfer the css to the inner print iframe
printHead.append($('style').clone());
//$('#printArea').append($table);
function moveTable(){
var def = $.Deferred();
//relocate the table to iframe's document
$.when(printBody.append($table)).then(function(){
def.resolve();
});
return def.promise();
}
//print button
var $btn = $('<button>Print</button>')
.on('click', function(){
//focus the doument and print on it
$('#printView').get(0).contentWindow.focus();
$('#printView').get(0).contentWindow.print();
});
$('#buttons').append($btn);
$.when(moveTable()).then(function(){
//all element in the iframe with css just needs their css modify to trigger off safari to update their css or sync with their css
//trick is to add a dummyClass and remove dummyClass on all elements
//iterate through all dom elements and hack css add/remove
$('*', printBody).each(function(){
var me = $(this);
if(me.attr('class')){
me.addClass("safariCssHack");
me.removeClass("safariCssHack");
}
});
/*//remove and add back class
var $imgs = $('img', printBody);
var classVal = $imgs.attr('class');
// $imgs.removeClass(classVal);
$imgs.addClass(classVal + " wall3");
*/
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.