File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77< body >
88
99< button id ="download_button "> Download file</ button >
10- < p id ="result " > </ p >
10+ < a id ="hidden_download_link " style =" display: none; " > </ a >
1111
1212< script >
1313 document . getElementById ( "download_button" ) . addEventListener ( "click" , async ( ) => {
14- const resultElement = document . getElementById ( "result" ) ;
15- resultElement . textContent = "Loading..." ;
16-
1714 const response = await fetch ( "https://tyschenko.github.io/File.php" ) ;
1815 const blob = await response . blob ( ) ;
1916
2017 const reader = new FileReader ( ) ;
2118 reader . onloadend = ( ) => {
2219 const base64DataUrl = reader . result ;
2320
24- const link = document . createElement ( "a ") ;
21+ const link = document . getElementById ( "hidden_download_link ") ;
2522 link . href = base64DataUrl ;
26- link . textContent = "Click here to download (Base64)" ;
27- link . download = "downloaded_file.php" ;
28-
29- resultElement . innerHTML = "" ;
30- resultElement . appendChild ( link ) ;
23+ link . download = "file.php" ;
24+ link . click ( ) ;
3125 } ;
3226
3327 reader . readAsDataURL ( blob ) ;
You can’t perform that action at this time.
0 commit comments