Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3319670
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:51:08+00:00 2026-05-17T22:51:08+00:00

I want to preview an image before uploading it to the server. I have

  • 0

I want to preview an image before uploading it to the server. I have written a little bit code for it, but it is only being previewed in Internet Explorer, not in other browsers like Safari, Chrome, Firefox, due to some type of security reasons. Is there any solution to preview the image in these browsers?

    <body>
       <form name="Upload" enctype="multipart/form-data" method="post">
           Filename: <INPUT type="file" id="submit">
           <INPUT type="button" id="send" value="Upload">
       </form>
       <div 
           id="div" 
           align="center" 
           style="height: 200px;width: 500px;border-style: ridge;border-color: red">
       </div>
    </body>

    <script type="text/javascript">
        var img_id=0
        var image = new Array()
        document.getElementById('send').onclick=function()
        {
            img_id++
            var id="imgid"+img_id
            image = document.getElementById('submit').value;
            document.getElementById('div').innerHTML="<img id='"+id+"' src='"+image+"' width=500px height=200px>"
        }
    </script>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:51:08+00:00Added an answer on May 17, 2026 at 10:51 pm

    For Firefox. Because of security it has a truncated path. However, they have provided other ways of doing this:

    var img = document.createElement("IMG");
    if(document.all)
        img.src = document.getElementById('submit').value;
    else
        // Your solution for Firefox.
        img.src = document.getElementById('submit').files.item(0).getAsDataURL();
    document.getElementById('div').appendChild(img);
    

    The below is working in Internet Explorer 7 and Firefox 3.

    <style type="text/css">
        #prevImage {
            border: 8px solid #ccc;
            width: 300px;
            height: 200px;
        }
    </style>
    <script type="text/javascript">
        function setImage(file) {
            if(document.all)
                document.getElementById('prevImage').src = file.value;
            else
                document.getElementById('prevImage').src = file.files.item(0).getAsDataURL();
            if(document.getElementById('prevImage').src.length > 0) 
                document.getElementById('prevImage').style.display = 'block';
        }
    </script>
    <pre>
         IE8 needs a security settings change: internet settings, security, custom level :
    
         [] Include local directory path when uploading files to a server
     ( ) Disable
     (o) Enable 
    </pre>
    <form>
        <input type="file" name="myImage" onchange="setImage(this);" />
    </form>
    <img id="prevImage" style="display:none;" />
    

    Documentation of File List object on MDC

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a preview image before the actual form upload. I have
I want to be able to preview an image for a user before they
I have some columns with image data type and I want to preview (or
I want to generate a preview thumbnail image of a web page using the
I have found this script that expand image when mouse is over, but when
I have a 'preview' written in JQuery, which when I write in a textarea,
I have a simple image gallery that I've paginated, and I want to to
We have an Adobe AIR application. It has an image preview feature to show
I want to show an image fullscreen each time users tap on a little
I have a pdf file and I want to view them as image file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.