Page 1 of 1

TWebView y Javascript

Posted: Thu Jul 13, 2023 7:06 pm
by EASYSOFT
Buenas tardes.

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

Muchas gracias.

Re: TWebView y Javascript

Posted: Fri Jul 14, 2023 12:32 am
by leandro

Re: TWebView y Javascript

Posted: Fri Jul 14, 2023 6:33 pm
by EASYSOFT
Leandro
Muchas gracias

Re: TWebView y Javascript

Posted: Sun Jul 16, 2023 8:06 pm
by EASYSOFT
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 = '_'
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.

Re: TWebView y Javascript

Posted: Sun Jul 16, 2023 11:14 pm
by cnavarro
Efectivamente, necesitas un servidor Web que esté corriendo en tu máquina
Puedes probar a instalar Apache ( Xampp ) o simplemente el httpd de harbour

Re: TWebView y Javascript

Posted: Mon Jul 17, 2023 7:36 am
by Antonio Linares
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.

Re: TWebView y Javascript

Posted: Mon Jul 17, 2023 3:03 pm
by EASYSOFT
Cristóbal , Antonio
Muchas gracias seguire investigando

Saludos