Safari browser is experiencing issues with the custom file upload script

My custom upload script allows users to easily select images for upload by clicking or dragging them into the designated box. A preview of the chosen image should appear, and this functionality works smoothly in Firefox and Chrome. However, I've encountered an issue with Safari. Since my client primarily uses Safari, it's crucial for me to ensure that this feature works seamlessly on that browser as well.

I'm curious as to why the script doesn't seem to function properly in Safari.

Here is the corresponding HTML code:

<form method='post' enctype='multipart/form-data' action='#'>
<div style="height: 200px;">
<div class="droparea spot logoupload">
<div class="instructions"><img class="previewlogo" src="http://wmemusic.com/wme/admin/img/loginlogo.jpg" alt="Click or Drag image here to add login logo"/>
</div>
<input type="file" class="droparea spot logoupload" name="logo" onchange="readURL(this);"/>
</div>
</div>
</form>

The CSS styling being applied is as follows:

.droparea {
                position:relative;
                text-align: center;
                min-height:100px;
                margin:0;
            }

            .droparea div, .droparea input {
                position: absolute;
                top:0;
                right:2px;
                width: 100%;
                height: 100%;
            }
            .droparea input {
                cursor: pointer; 
                opacity: 0; 
            }
            .droparea .instructions {
                border: 2px dashed #ddd;
                max-height:200px;
                height:auto;
                min-height:100px;
                overflow:hidden
            }
            .droparea .instructions.over {
                border: 2px dashed #000;
                background: #ffa;
            }


            #areas { width: 480px; }
            div.spot {

                margin: 5px auto;

            }
          .logoupload {width: 262px;
                min-height: 100px;
                height:auto;}

And here is the accompanying JavaScript snippet:

function readURL(input) {
if (input.files && input.files[0]) {
    var reader = new FileReader();
    var imgHeight = $(".previewlogo").height();

    reader.onload = function(e) {
        $('.previewlogo').attr('src', e.target.result)
        $('.droparea').attr('style', 'height:', imgHeight, 'px;')
    };

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

Answer №1

Unfortunately, Safari does not yet support FileReader functionality. You can check compatibility here: http://caniuse.com/#search=filereader

UPDATE: Good news! Safari 6.0+ now supports FileReader on both iOS and Desktop platforms.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can we align the top edge of a div to the center of a circle within a separate div in a responsive manner?

I want to create 2 stacked divs: the first div contains a circular image, and the second div contains text. I want the second div to always cover half of the circle, with its upper edge positioned at the center point of the circle. This is my code: .cov ...

The functionality of the String prototype is operational in web browsers, but it encounters issues

Version: 8.1.0 The prototype I am working with is as follows: String.prototype.toSlug = function () { return (<string>this) .trim() .toLowerCase() .replace(/\s+/g, '-') .replace(/[^\w\-]+/g, '') ...

Enabling communication between JavaScript and PHP and vice versa

I am currently working on developing a Firefox plug-in with the purpose of gathering all the domains from the links located on the current site and showcasing their respective IP addresses. In order to achieve this, I have written JavaScript code that incl ...

Does v-if cause the jquery clock picker to malfunction?

Here is my unique div where the clockpicker library functions correctly. <div class="input-group clockpicker"> <input type="text" class="form-control" value="18:00"> <span class="input-group-addon"> <span class ...

What is the process for "dereferencing" an object?

How can you access the properties of an object returned by a function in JavaScript? For instance: var tmp = getTextProperties(); font = tmp.font; size = tmp.size; color = tmp.color; bold = tmp.bold; italic = tmp.italic; While PHP offers the list ...

Navigating with router.push in Vue.js to the same path but with different query parameters

The existing URL is /?type=1 I am attempting to implement router.push on this specific page. this.$router.push('/?type=2'); However, it results in a NavigationDuplicated error. I prefer not to utilize parameters such as /:type ...

The selected text on the webpage is not showing up highlighted

Encountering an unusual issue that is challenging to comprehend and difficult to find a solution for using Google search. I have created a website with multiple web pages. Each page follows the same format: header with links at the top, content area in th ...

Tips on how to pass properties as arguments to mixins

Here is the code I have: mox(first, second) {first} second a mox(transition, 0.3s linear all) I want to call the mixin like this: mox(transition 0.3s linear all) If we modify mox, it would look like this: mox() arguments a mox transition 0.3 ...

Upload file via AJAX immediately after downloading it (no need for storage)

Currently, I am in the process of developing a JavaScript script to safeguard an old game development sandbox website from being discarded by its owners. In order to prevent the loss of all the games on the site, I have managed to create a script that allo ...

Angular: Disabling a button based on an empty datepicker selection

Can anyone help me figure out how to disable a button when the datepicker value is empty? I've tried using ngIf to check if the datepicker is empty and then disable the button, but it's not working. My goal is to make the button unclickable if th ...

Repeated calls to Angular's <img [src]="getImg()"> frequently occur

Can someone help me figure out what's going on here? Recently, I set up a new Angular project and in app.component.html, I have the following code: <img [src]="getDemoImg()"> In app.component.ts: getDemoImg(){ console.log('why so m ...

How can I get electron to interact with sqlite3 databases?

I've exhausted all my options and still can't get it to function. This error message keeps popping up: https://i.stack.imgur.com/D5Oyn.png { "name": "test", "version": "1.0.0", "description": "test", "main": "main.js", "scripts": { ...

The display of temporary headers - Nodemailer - AJAX

I keep receiving a warning in the request header that says: Provisional headers are shown. I'm struggling to identify the root cause of this issue. This warning prevents the readyState from changing and my callbacks on the eventhandler onreadystatecha ...

How about trying out the magic of Bootstrap columns?

My issue pertains to bootstrap columns. Whenever I zoom in on the browser, the columns start overlapping and the text from col-md-7 ends up over the image. Does anyone know of a solution to this problem? <div class="row"> <div class="col-md-5 ...

Tips for preventing JavaScript errors when making cross-domain requests using AJAX

Is there a way to prevent or handle JavaScript errors without causing the script to crash? Error message: No data returned $.ajax({ type : 'GET', dataType : 'jsonp', url : '//cvrapi.dk/api?search=dsfsdfsd&country= ...

Why won't my code work with a jQuery selector?

I'm struggling to retrieve the value from a dynamically generated <div> using jQuery. It seems like the syntax I'm using doesn't recognize the div with an id tag. The HTML code is stored in a variable, and below is a snippet of code w ...

What is the best way to center the input on the page?

Does anyone know how to align the <input type="text"> in the center? I'm trying to create a login form but having trouble with positioning the input element. ...

`Loading CSS and JS files in node.js: A step-by-step guide`

I've searched through numerous similar questions without success, so I'm reaching out for help. My folder structure looks like this: Source Code Frontend Graphs.html Graphs.css Temperature.js Server_Backend server.js I aim ...

jQuery's draggable and resizable functionality with containment provisions is designed to

I'm struggling to create a resizable and draggable div using jQuery, but it's proving to be quite buggy in its implementation. Despite finding similar questions, I haven't come across a solution yet. How can I fix the containment bug when ...

Ajax Multidimensional Array Response

Currently, I am attempting to retrieve a Multiarray response from an ajax Post JSON request. After numerous attempts, I am hopeful that I can get assistance here... JS AJAX RESPONSE var data = { "myid": "1234" }; $(".the-return").html(""); $.ajax({ ...