SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    File upload trick doesn't work in Safari

    Hi,

    I am using the following to upload a file.

    Code:
    <button type="button" id="mybutton">Upload</button>
    <input type="file" id="myfile" style="display:none" />
    with

    Code:
    $('#mybutton').click(function () {
    	$('#myfile').trigger('click');
    });
    This works fine on Firefox and Chrome but not on Safari (v5.1.7 on Windows Vista). Any ideas how to make it work on Safari too?

    Thanks.

  2. #2
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,296
    Mentioned
    179 Post(s)
    Tagged
    6 Thread(s)
    Does it work if you use visibility:hidden instead of display:none?

    Code:
    <input type="file" id="myfile" style="visibility:hidden;height:0;width:0;overflow:hidden" />
    Or perhaps just move it off-screen.

    Won't that leave the user without knowing what file they have selected?

  3. #3
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea, it worked with "visibility: hidden". Thank you.

    Won't that leave the user without knowing what file they have selected?
    Thanks for pointing that out but it is not an issue in my case.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •