xxxxxxxxxx
function handleDownloadPDF(fileUrl: string, fileName: string) {
if (!fileUrl || !fileName) return;
fetch(fileUrl)
.then((response) => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.blob();
})
.then((blob) => {
const url = window.URL.createObjectURL(blob);
const tmp1 = document.createElement("a");
tmp1.href = url;
tmp1.download = `${fileName}.pdf`;
document.body.appendChild(tmp1);
tmp1.click();
tmp1.remove();
window.URL.revokeObjectURL(url);
})
.catch((error) => {
console.error("There was an issue with downloading the image:", error);
});
}
xxxxxxxxxx
import axios from 'axios'
import fileDownload from 'js-file-download'
handleDownload = (url, filename) => {
axios.get(url, {
responseType: 'blob',
})
.then((res) => {
fileDownload(res.data, filename)
})
}
<button onClick={() => {this.handleDownload('https://your-website.com/your-image.jpg', 'test-download.jpg')
}}>Download Image</button>
xxxxxxxxxx
import React from "react";
import { saveAs } from "file-saver";
export default function App() {
const saveFile = () => {
saveAs(
"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
"example.pdf"
);
};
return (
<div>
<button onClick={saveFile}>download</button>
</div>
);
}
xxxxxxxxxx
fetch('https://cors-anywhere.herokuapp.com/' + fileURL, {
method: 'GET',
headers: {
'Content-Type': 'application/pdf',
},
})
.then((response) => response.blob())
.then((blob) => {
// Create blob link to download
const url = window.URL.createObjectURL(
new Blob([blob]),
);
const link = document.createElement('a');
link.href = url;
link.setAttribute(
'download',
`FileName.pdf`,
);
// Append to html link element page
document.body.appendChild(link);
// Start download
link.click();
// Clean up and remove the link
link.parentNode.removeChild(link);
});
xxxxxxxxxx
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Something went wrong!',
})
xxxxxxxxxx
var fileDownload = require('js-file-download');
fileDownload(data, 'filename.csv');
xxxxxxxxxx
Swal.fire({
icon: 'success',
title: 'Your work has been saved',
showConfirmButton: false,
timer: 1500
})
xxxxxxxxxx
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
})
xxxxxxxxxx
<head>
<script src="jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
</head>
<?php
echo '
<script type="text/javascript">
$(document).ready(function(){
swal({
position: "top-end",
type: "success",
title: "Your work has been saved",
showConfirmButton: false,
timer: 1500
})
});
</script>
';
?>
sweet alert use
xxxxxxxxxx
Swal.fire({
title: 'Error!',
text: 'Do you want to continue',
icon: 'error',
confirmButtonText: 'Cool'
})