Skip to content

Instantly share code, notes, and snippets.

@Cloud-Awesome
Last active June 16, 2021 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cloud-Awesome/6bb2c0ef0e5d05c743f71160189e0ceb to your computer and use it in GitHub Desktop.
Save Cloud-Awesome/6bb2c0ef0e5d05c743f71160189e0ceb to your computer and use it in GitHub Desktop.
[...]
<div id="csv_data"></div>
<script type="text/javascript">
// '/odata-web-pages' is where I published the sample FetchXml-generated feed
fetch("/odata-web-pages?website-id={{ request.params['website-id'] }}")
.then(response => response.json())
.then((data) => {
const link = document.createElement("a");
const linkText = "Download Csv file";
let csvContent = "data:text/csv;charset=utf-8," + encodeURIComponent(data.map(e => e.join(",")).join("\n"))
link.append(linkText);
link.setAttribute("href", csvContent);
link.setAttribute("download", "your_csv_data_file.csv");
link.setAttribute("title", "WebPage CSV Download");
$("#csv_data").append(link);
})
.catch((error) => {
console.error('Do something with this error:', error);
});
</script>
[...]
@Cloud-Awesome
Copy link
Author

Updated line 13 to encodeURIComponent CSV content. This handles special characters such as # which prevented full download

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment