How to set download filename on Google Chrome for iOS by javascript
Asked Answered
C

0

6

I could not manage to work the download attribute when downloading vcards via data URL by Chrome on IOS. I use code below

function download(filename, text) {
        var element = document.createElement('a');
        element.setAttribute('href', 'data:text/vcard;charset=utf-8,' + encodeURIComponent(text));
        element.setAttribute('download', filename);
        element.style.display = 'none';
        document.body.appendChild(element);
        element.click();
        document.body.removeChild(element);
    }

It works fine with Safari on IOS and Chrome on Android. But Chrome on IOS just ignore file name and download file just with name "document" so in not opened by contact app.

Cake answered 15/8, 2021 at 18:42 Comment(2)
Did you manage to solve this? Facing the same issue at the moment!Rrhoea
As of 2021-12-16, looks like setting the filename is not possible on Chrome on iOS. See bugs.webkit.org/show_bug.cgi?id=167341#c66.Policyholder

© 2022 - 2024 — McMap. All rights reserved.