ICS download link does not work on Microsoft browser (including edge)
dogawaf opened this issue · 6 comments
The ICS download link proposed by this library does not work on Microsoft browsers because they do not support navigating to data uri:
For security reasons, data URIs are restricted to downloaded resources. Data URIs cannot be used for navigation, for scripting, or to populate frame or iframe elements.
source: https://docs.microsoft.com/en-us/previous-versions//cc848897(v=vs.85)
@dogawaf
There is nothing to do within this lib. But you can bypass it: redirect user to a route to download a file instead
I would not ask you to fix IE limitations :)
But at least the limitation should be documented here.
More insights:
- The issue on edge tracker: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/4282810/
- Blog article from a Microsoft dev: https://textslashplain.com/2018/08/06/script-generated-download-files/
- Test page: https://bayden.com/test/data.htm
There is also this JS library that may help: http://danml.com/download.html
done: added to the bottom of the Usage section: https://github.com/spatie/calendar-links#usage, thanks a lot @dogawaf !
Does it work on the chromium based Edge browsers?
Use download.js version 1.4.8 to trigger ics file download in the browser - it works in Internet Explorer!
PHP:
$link = Link::create('My Event', $from, $to);
echo '<a href="' . $link->ics() . '" class="ics-link">Download My Event</a>';
jQuery:
$('.ics-link').click(function (event) {
var href = $(this).attr('href');
download(href, 'download.ics');
event.preventDefault();
});
Full docs: https://github.com/rndme/download
Hey @wxactly
Let me improve (a bit) your solution and rely on download
attribute instead of .ics-link
:
$link = Link::create('My Event', $from, $to);
echo '<a href="' . $link->ics() . '" class="ics-link" download="event.ics">Download My Event</a>';
$('a[download]').click(function (event) {
var href = $(this).attr('href');
var storeAsFilename = $(this).attr('download') || 'event.ics';
download(href, storeAsFilename);
event.preventDefault();
});
UPD: or with less jQuery:
$('a[download]').click(function (event) {
/** @type {HTMLAnchorElement} */
var anchor = event.target;
var storeAsFilename = anchor.download || 'event.ics';
download(anchor.href, storeAsFilename);
event.preventDefault();
});