Skip to content

Instantly share code, notes, and snippets.

@sakunyo
Created July 26, 2011 02:01
Show Gist options
  • Save sakunyo/1105770 to your computer and use it in GitHub Desktop.
Save sakunyo/1105770 to your computer and use it in GitHub Desktop.
js image onload print
(function(){
var loc = document.location.search,
t = new Date(),
img = new Image(),
src = '';
if(loc.indexOf('page=hoge') > -1){
src = 'images/hoge/print.jpg'+'?'+t.getTime();
}else if(loc.indexOf('page=fuga') > -1){
src = 'images/fuga/print.jpg'+'?'+t.getTime();
};
if(src !== ''){
img.alt = '';
img.src = src;
img.onload = function(){
document.getElementsByTagName('body')[0].appendChild(img);
setTimeout( function(){
window.print();
},300);
};
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment