FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour TWebView y Javascript
Posts: 195
Joined: Sat Oct 22, 2005 01:17 PM
TWebView y Javascript
Posted: Thu Jul 13, 2023 07:06 PM

Buenas tardes.

Alguien que me pueda ayudar con un ejemplo sencillo que ejecute una función javascript desde un boton

utilizando TWebView

Muchas gracias.

Saludos

Oscar

Fwh 23.10, bcc55

Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Re: TWebView y Javascript
Posted: Fri Jul 14, 2023 12:32 AM
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]
Posts: 195
Joined: Sat Oct 22, 2005 01:17 PM
Re: TWebView y Javascript
Posted: Fri Jul 14, 2023 06:33 PM

Leandro

Muchas gracias

Saludos

Oscar

Fwh 23.10, bcc55

Posts: 195
Joined: Sat Oct 22, 2005 01:17 PM
Re: TWebView y Javascript
Posted: Sun Jul 16, 2023 08:06 PM

Estimados buenas tardes

Estoy tratando de ejecutar la siguiente funcion javascript con TWebView pero no me funciona

include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

local oWebView := TWebView():New()

oWebView:Center()

oWebView:bOnBind = { | cJson, cCalls | MsgInfo( cJson, cCalls ),;

                    oWebView:Return( cCalls, 0, "{ 'result': 'Hello from PRG' }" ) }

oWebView:Bind( "SendToFWH" )

oWebView:Navigate( Html() )

Sleep( 200 )

oWebView:Run()

oWebView:Destroy()

return nil

//----------------------------------------------------------------------------//

function Html()

local cHtml

TEXT INTO cHtml

  data:text/html,

  <head><body>

  <button id='btn-test' >Click Me</button>

  <script>

  function test(evt) {



    var response = [];

    var pwd_p12 =  '12345'

    respuesta = 'oscar'

    window.contenido_comprobante = respuesta;

    var oReq = new XMLHttpRequest();

  //  alert(oReq.readyState );

  //  alert(this.status );

    var ruta_certificado = 'c:\archivo.p12';

    oReq.open("GET",ruta_certificado , true);

  //   alert(oReq.readyState );

    oReq.responseType = "arraybuffer";

    oReq.send();

    alert(oReq.readyState );

    alert( oReq.response);

    oReq.onload = function (oEvent) {

        var blob = new Blob([oReq.response], {type: "application/x-pkcs12"});

        window.contenido_p12 = [oReq.response];

        console.log(window.contenido_p12)

    }

     // alert( oReq.status );

     // alert( oReq.response );



  }

  document.getElementById('btn-test').addEventListener('click', test);



  </script>

  </head></body>

ENDTEXT

return cHtml

Al parecer esta funcion XMLHttpRequest() trabaja teniendo un servidor web no estoy seguro, quiza me puedan orientar a ver si se puede

o como lo podria hacer con fwh

Muchas gracias.

Saludos

Oscar

Fwh 23.10, bcc55

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: TWebView y Javascript
Posted: Sun Jul 16, 2023 11:14 PM

Efectivamente, necesitas un servidor Web que esté corriendo en tu máquina

Puedes probar a instalar Apache ( Xampp ) o simplemente el httpd de harbour

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TWebView y Javascript
Posted: Mon Jul 17, 2023 07:36 AM
respuesta de chatGPT:
Use a local web server: Running a local web server allows you to serve your files over HTTP, which helps bypass the same-origin policy restrictions. There are several lightweight web servers available that you can install and run locally, such as Node.js with Express, Python's SimpleHTTPServer, or the Live Server extension for Visual Studio Code.

Disable web security in your browser: Another option is to disable web security in your browser temporarily for testing purposes. Keep in mind that this approach is not recommended for regular browsing due to security implications. In Chrome, you can start the browser with the --disable-web-security flag to disable the same-origin policy. However, exercise caution when using this method.

Use a browser extension: Some browser extensions, like CORS Unblock, allow you to bypass the same-origin policy by adding appropriate CORS headers to requests. These extensions modify the headers of the requests you make, enabling you to access resources from different domains.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 195
Joined: Sat Oct 22, 2005 01:17 PM
Re: TWebView y Javascript
Posted: Mon Jul 17, 2023 03:03 PM

Cristóbal , Antonio

Muchas gracias seguire investigando

Saludos

Saludos

Oscar

Fwh 23.10, bcc55

Continue the discussion