Since you checked this html5 , you understand that this is an advanced browser feature.
What you ask for will require FileReader, available in most of all modern browsers (even IE).
// Bind to the change event of our file input $("input[name='myFileSelect']").on("change", function(){ // Get a reference to the fileList var files = !!this.files ? this.files : []; // If no files were selected, or no FileReader support, return if ( !files.length || !window.FileReader ) return; // Only proceed if the selected file is an image if ( /^image/.test( files[0].type ) ) { // Create a new instance of the FileReader var reader = new FileReader(); // Read the local file as a DataURL reader.readAsDataURL( files[0] ); // When loaded, set image data as background of page reader.onloadend = function(){ $("html").css("background-image", "url(" + this.result + ")"); } } });β
I just tested the above code in Internet Explorer 10, Chrome 19/21, Firefox 12/13 and Opera 11.64 and found that it worked without problems.
Older browsers that do not support FileReader will simply be silent. There are no images, there were no exceptions.
Fiddle: http://jsfiddle.net/jonathansampson/K3A9r/
Sampson
source share