5 Replies - 620 Views - Last Post: 24 May 2012 - 10:18 PM

#1 drayarms  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 169
  • Joined: 18-May 11

Cross browser compatibility issues with image preview script.

Posted 24 May 2012 - 12:17 PM

Hello, It's my first time attempting this. After searching around the web, I came across this script which does what I'm trying to accomplish (ie preview a picture before it is downloaded) but only works for Firefox and Opera. Does anyone know how this code can be modified to make it cross browser compatible? Or does anyone have a better working example? Thanks.

	

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML1.0 Transitional//EN"



"http//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 


<html xmlns="http://www.w3.org/1999/xhtml"> 


	<head> 

		<script type = "text/javascript" src="http://code.jquery.com/jquery-latest.js"> </script>


		<script type="text/javascript">

        		function readURL(input) {

            			if (input.files && input.files[0]) {

                			var reader = new FileReader();

                			reader.onload = function (e) {

                    				$('#blah').attr('src', e.target.result);

                			}

                			reader.readAsDataURL(input.files[0]);

            			}

        		}

    		</script>



	</head>


	<body>


		<form id="form1" runat="server" enctype="multipart/form-data">

        		<input type='file' onchange="readURL(this);" />

        		<img id="blah" src="#" width = "300px" max-height = "340px" alt="your image" />

    		</form>


	</body>



</html>




Is This A Good Question/Topic? 0
  • +

Replies To: Cross browser compatibility issues with image preview script.

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2894
  • View blog
  • Posts: 7,541
  • Joined: 08-June 10

Re: Cross browser compatibility issues with image preview script.

Posted 24 May 2012 - 12:55 PM

according to MDN it should be more or less supported in all browsers.
Was This Post Helpful? 0
  • +
  • -

#3 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3044
  • View blog
  • Posts: 4,556
  • Joined: 08-June 10

Re: Cross browser compatibility issues with image preview script.

Posted 24 May 2012 - 01:07 PM

Only in IE10, though, it appears. I don't see a way to use that IE9 Lab stuff with an input element.
Was This Post Helpful? 0
  • +
  • -

#4 drayarms  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 169
  • Joined: 18-May 11

Re: Cross browser compatibility issues with image preview script.

Posted 24 May 2012 - 04:15 PM

@drmilich and atli, have u fellows tested it in your browsers? Just in case I might be using outdated versions though I don't think so.
Was This Post Helpful? 0
  • +
  • -

#5 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3044
  • View blog
  • Posts: 4,556
  • Joined: 08-June 10

Re: Cross browser compatibility issues with image preview script.

Posted 24 May 2012 - 10:09 PM

Yea, I tested it in all the browsers I have at home, and it works in all but IE and Safari.

That is, it works in:
- Firefox 12.0
- Chrome 19.0 and 20.0 (beta)
- Opera 11.61

But not in:
- Internet Explorer 9
- Safari 5.1.3 (OSX)
Was This Post Helpful? 0
  • +
  • -

#6 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3044
  • View blog
  • Posts: 4,556
  • Joined: 08-June 10

Re: Cross browser compatibility issues with image preview script.

Posted 24 May 2012 - 10:18 PM

Guess I should have done some Googling before testing it myself :)

When can I use FileReader API?


By the way, MDN is wrong in their browser support table. Safari 5.1 does NOT support the FileReader API.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1