Created
July 26, 2011 02:01
-
-
Save sakunyo/1105770 to your computer and use it in GitHub Desktop.
js image onload print
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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