export const downloadFileWithIframe = (url, name) => {
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.style.height = 0;
iframe.name = name;
iframe.src = url;
document.body.appendChild(iframe);
setTimeout(() => {
iframe.remove();
}, 5 * 60 * 1000);
};
export const downloadFileWithWindow = (url, name) => {
const otherWindow = window.open(url, name);
otherWindow.opener = null;
};
export function handleWindowDownload(url, data, name) {
if (!url) return;
let paramStr = '';
if (data && typeof data === 'object') {
const keys = Object.keys(data);
const arr = [];
if (keys.length > 0) {
keys.forEach(item => {
arr.push(`${item}=${data[item]}`);
});
}
paramStr = arr.join('&');
}
url += paramStr ? `?${paramStr}` : '';
downloadFileWithWindow(`${url}`, name);
}
export function openPostWindow(url, name, data1) {
var tempForm = document.createElement('form');
tempForm.id = 'tempForm1';
tempForm.method = 'post';
tempForm.action = url;
tempForm.target = name;
var hideInput1 = document.createElement('input');
hideInput1.type = 'hidden';
hideInput1.name = 'data';
hideInput1.value = data1;
tempForm.appendChild(hideInput1);
if (document.all) {
tempForm.attachEvent('onsubmit', function() {});
} else {
tempForm.addEventListener('submit', function() {}, false);
}
document.body.appendChild(tempForm);
if (document.all) {
tempForm.fireEvent('onsubmit');
} else {
tempForm.dispatchEvent(new Event('submit'));
}
tempForm.submit();
document.body.removeChild(tempForm);
}