FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index mod_harbour Verificar si existe el archivo y lanzar
Posts: 1074
Joined: Fri Oct 07, 2005 01:56 PM
Verificar si existe el archivo y lanzar
Posted: Tue Jul 13, 2021 02:13 AM
Estimados

como puedo saber si existe el archivo antes de lanzar el PDF

he tratado de buscar en la web pero no lo he podido lograr

Code (fw): Select all Collapse
BUTTON ID 'btnprint'  LABEL ' Print'  ACTION 'PrintPdf()' GRID 2 ICON '<i class="fas fa-home"></i>' CLASS 'btn-primary btnticket' OF o


Code (fw): Select all Collapse
<script>
               
                function PrintPdf() {
                  if existarchivo( 'cFileName.Pdf' )
                    window.open('cFileName.Pdf' );
                 }
Saludos
Patricio

__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Verificar si existe el archivo y lanzar
Posted: Tue Jul 13, 2021 11:26 PM

Hello,
Please search for: javascript check file exists on server
I found: How do I check if file exists in jQuery or pure JavaScript?

https://stackoverflow.com/questions/364 ... javascript
Best regards,
Otto

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Verificar si existe el archivo y lanzar
Posted: Tue Jul 13, 2021 11:53 PM
Code (fw): Select all Collapse
function main

TEMPLATE
<!DOCTYPE html>
<html>
<head>
</head>
<body>
    
    <h1>Test open PDF</h1>
    <button onclick="myFunction()">Open PDF</button>
    
    <script>
        function myFunction() {
            var url = "https://winhotel.space/modharbour_samples/test.pdf";

            if ( fileExists( url ) ){
            var myWindow = window.open("https://winhotel.space/modharbour_samples/test.pdf", "", "width=400,height=400");
            }else{
            alert("file not found");                
            }
               
        }
        
        
        function fileExists(url) {
            if(url){
                var req = new XMLHttpRequest();
                req.open('GET', url, false);
                req.send();
                return req.status==200;
            } else {
                return false;
            }
        }
        
    </script>
    
</body>
</html> 

ENDTEXT

return
Posts: 1074
Joined: Fri Oct 07, 2005 01:56 PM
RESUELTO Re: Verificar si existe el archivo y lanzar
Posted: Wed Jul 14, 2021 02:57 AM

Gracias Otto

FUNCIONO!!!

Saludos
Patricio

__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl

Continue the discussion