Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filename attr is not woking in Safari #29

Open
jeonghwan-kim opened this issue May 27, 2014 · 39 comments
Open

filename attr is not woking in Safari #29

jeonghwan-kim opened this issue May 27, 2014 · 39 comments

Comments

@jeonghwan-kim
Copy link

Thank you for this code (ng-csv). I used it in my project.

However, in Safari, csv file is not download. It is printed in Safari browser's new tab.
Aslo in Chrome browser filename attr is not working.

(Firefox is ok)

@asafdav
Copy link
Owner

asafdav commented May 27, 2014

Hi,
Thanks for the report, Apparently Google pushed a bug in the latest version
of Chrome.
https://code.google.com/p/chromium/issues/detail?id=376197

I hope they will solve this soon enough, I'll check up on this in the next
couple of days and if I won't see any progress I will try to find a
workaround.

On Tue, May 27, 2014 at 9:58 AM, jeonghwan notifications@github.com wrote:

Thank you for this code (ng-csv). I used it in my project.

However, in Safari, csv file is not download. It is printed in Safari
browser's new tab.
Aslo in Chrome browser filename attr is not working.

(Firefox is ok)


Reply to this email directly or view it on GitHubhttps://github.com//issues/29
.

@jeonghwan-kim
Copy link
Author

Thank you for comment. :D

@asafdav
Copy link
Owner

asafdav commented Jun 1, 2014

The Chromium team merged the issue into this one https://code.google.com/p/chromium/issues/detail?id=373182

It should be fixed in a week or two. let's cross our fingers.

@jeonghwan-kim
Copy link
Author

I expect.

@tinybigideas
Copy link

Same issue. Hoping for a resolution.

@asafdav
Copy link
Owner

asafdav commented Jun 17, 2014

According to issue above, they solved it today, so we should expect a fix soon.

@amit777
Copy link

amit777 commented Jun 25, 2014

I'm using chrome Version 35.0.1916.153 latest. When I click on export, it always choose "download.csv" as the filename even if I have the filename="export.csv" attribute set.

Also, I have the same issue as mentioned above where safari opens the CSV in a new tab.

@adityasabnis
Copy link

I am facing the same issue with Chrome and Safari. Do we have any work around at this moment?

@asafdav
Copy link
Owner

asafdav commented Jul 9, 2014

Hi,

I don't have a good solution for Safari at the moment, as currently they
ignore the html5 download attribute. We can try to find a good flash
polyfill that will allow us to bypass that, Downloadify seems like a good
option. If any of you have the time for it, I'll be more than happy to
accept a pull request :)

As I mentioned above, The chrome team already solved the issue and the next
version is just around the corner, If you use Chrome beta or Canary you can
already see the it's solved. I hope it's a matter of days.

On Wed, Jul 9, 2014 at 7:54 AM, Aditya Sabnis notifications@github.com
wrote:

I am facing the same issue with Chrome and Safari. Do we have any work
around at this moment?


Reply to this email directly or view it on GitHub
#29 (comment).

@jmtt89
Copy link

jmtt89 commented Jul 17, 2014

hi, for a rapid solution of chrome problem, you can modify ng-csv.js else in line 211 for that

    else {
        var blob = new Blob([scope.csv],{ 
              type: 'text/csv' 
            });
        var csvUrl = URL.createObjectURL(blob);

        var downloadLink = angular.element('<a></a>');
        downloadLink.attr('href',csvUrl);
        downloadLink.attr('download',scope.getFilename());

        $document.find('body').append(downloadLink);
        $timeout(function() {
          downloadLink[0].click();
          downloadLink.remove();
        }, null);
      }

@asafdav
Copy link
Owner

asafdav commented Aug 19, 2014

UPDATE: The latest version of chrome works as expected

@jeonghwan-kim
Copy link
Author

Thanks I will check it.

@asafdav asafdav changed the title filename attr is not woking in Safari and Chrome filename attr is not woking in Safari Oct 1, 2014
@Hesesses
Copy link

Hesesses commented Sep 8, 2015

Any updates about this? On safari i will get printed output, not a downloaded file..

@mwager
Copy link

mwager commented Sep 11, 2015

Same here, safari doesn't download the file. Any idea how to work around this issue?

@alexey-shaposhnikov
Copy link

how it's going?

@jeonghwan-kim
Copy link
Author

This is because Safari doesn't allow downloading of blob urls. So FileSaver.js using base64data in case of Safari browser. How about using this code on Safari in our project?

if (isSafari()) {
    downloadContainer = angular.element('<div data-tap-disabled="true"><a></a></div>');
    downloadLink = angular.element(downloadContainer.children()[0]);

    // Safari doesn't allow downloading of blob urls
    var reader = new FileReader();
    reader.readAsDataURL(blob);
    reader.onloadend = function() {
        var base64data = reader.result;
            downloadLink.attr('href', 'data:attachment/file' + base64data.slice(base64data.search(/[,;]/)));
        };

        $document.find('body').append(downloadContainer);
        $timeout(function () {
            downloadLink[0].click();
            downloadLink.remove();
        }, null);
}        

jeonghwan-kim added a commit to jeonghwan-kim/ng-csv that referenced this issue Dec 27, 2015
@ghost
Copy link

ghost commented Feb 22, 2016

Has there been any progress on this issue?

@ghost
Copy link

ghost commented Feb 23, 2016

So I've been doing some research into this. It looks like Safari doesn't support the download attribute used in the dynamically created element in the directive's link function. From what I've been able to find, other developers have either directed their users through non-intuitive right-click then "save page as" or create a content stream that still results in losing the filename. I'll keep looking into this and if I find a work around or something that looks like it fits into ng-csv's without a lot of bloat I'll let yall know / make a pull request.

@ghost
Copy link

ghost commented Feb 24, 2016

I'm afraid I've had something higher priority come up but if I have a chance I'll get back to this.

@id0Sch
Copy link

id0Sch commented Mar 1, 2016

@asafdav - seems that Chrome 48.0.2564.116m on windows10 still doesn't have extname on the file.

@diego-oliveira
Copy link

It's working like a charm on chrome.
However, in Safari, csv file is not download yet. I'll try find a solution for it and make a PR guys.
BTW... great work on this directive! 👏

@diego-oliveira
Copy link

@jeonghwan-kim I tried your code but unfortunately it didn't worked. Did you find a solution for it?

@patioheaven
Copy link

  • one same problem in safari. Thanks @diego-oliveira, let us know if you find anything. ;-)

@jnelson
Copy link

jnelson commented Apr 21, 2016

@diego-oliveira : @jeonghwan-kim 's solution works fine when taken as a whole.

@asafdav If there's something wrong with the above (besides that it's not a pull request) or with @karrde00 's pull request, please comment on them - I'd be happy to help clean up, etc., if needed.

@diego-oliveira
Copy link

@jnelson I'll give it a shoot again and see if it was some mistake from my side. Thanks.

@jnelson
Copy link

jnelson commented Apr 21, 2016

@diego-oliveira If you prefer the iframe approach, we have an up-to-date merge of @karrde00's pull request at https://github.com/xlhybridsOSS/ng-csv/tree/github_karrde00-master - initial testing against IE11 and Safari 9.1 for our immediate problem has been successful.

@leongaban
Copy link

Thanks guys for working on this! We just ran into an issue where a client tried to download our data in CSV on Safari and it did not work :(

@d0dge
Copy link

d0dge commented Jun 4, 2016

Has anyone managed to get either of the above solutions working on Safari for iPad / iPhone? Nothing happens when I click my save button using @jeonghwan-kim 's solution and I get an "unable to read file" error using @karrde00 's solution.

I also cannot download using the Android built-in browser, using any solution. It works in Chrome for Android though. Haven't seen anyone else mention this problem...

@roccomuso
Copy link

+1

5 similar comments
@Lasto13
Copy link

Lasto13 commented Dec 5, 2016

+1

@farhanlatheef
Copy link

+1

@lucaswhitman
Copy link

+1

@ghilton000
Copy link

+1

@ryankidd
Copy link

+1

@Novarg
Copy link

Novarg commented Apr 6, 2017

downloadLink.attr('target', '_blank'); line prevent safari from downloading file. With this line it opens file in new tab while without it safari downloading file as expected.

@henrique2601
Copy link

+1, any news?

@Fercho191
Copy link

@Novarg I tried commenting on that line that you mention and it works in Safari and Chrome, you should do a pull request with that change

@jokingzhang
Copy link

+1

1 similar comment
@imcarvalho
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests