Skip to content

Commit 381ba99

Browse files
author
shiey
committed
🔧 Improve download handling: Force download in new window and enhance user feedback during download process
1 parent 254b4fe commit 381ba99

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

‎static/script.js‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,31 @@ class FacebookVideoDownloader {
108108

109109
downloadLink.href = streamUrl;
110110
downloadLink.download = fileName;
111-
downloadLink.target = '_blank'; // Force new tab if download fails
112111

113-
// Add click handler to ensure download works properly
112+
// Force download on click by opening in new window
114113
downloadLink.onclick = (e) => {
115-
// Let the browser handle the download naturally first
116-
// If that fails, the target="_blank" will open in new tab
117-
console.log('Download triggered:', streamUrl);
114+
e.preventDefault();
115+
116+
// Show downloading state
117+
downloadLink.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i>Downloading...';
118+
downloadLink.style.pointerEvents = 'none';
119+
120+
// Open the download URL in a new window/tab
121+
// This forces the browser to treat it as a download
122+
const downloadWindow = window.open(streamUrl, '_blank');
123+
124+
// Reset button after a short delay
125+
setTimeout(() => {
126+
downloadLink.innerHTML = '<i class="fas fa-download mr-2"></i>Download Now';
127+
downloadLink.style.pointerEvents = '';
128+
129+
// Close the download window if it's still open (some browsers keep it open)
130+
if (downloadWindow) {
131+
downloadWindow.close();
132+
}
133+
}, 2000);
118134

119-
// Optional: You can add tracking or analytics here
120-
return true; // Allow default behavior
135+
return false;
121136
};
122137

123138
this.results.classList.remove('hidden');

0 commit comments

Comments
 (0)