TWebView y Javascript

Post Reply
EASYSOFT
Posts: 190
Joined: Sat Oct 22, 2005 1:17 pm
Location: Quito - Ecuador

TWebView y Javascript

Post 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.
Saludos
_
Fwh 10.4, bcc55
User avatar
leandro
Posts: 1688
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia
Contact:

Re: TWebView y Javascript

Post by leandro »

Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
EASYSOFT
Posts: 190
Joined: Sat Oct 22, 2005 1:17 pm
Location: Quito - Ecuador

Re: TWebView y Javascript

Post by EASYSOFT »

Leandro
Muchas gracias
Saludos
_
Fwh 10.4, bcc55
EASYSOFT
Posts: 190
Joined: Sat Oct 22, 2005 1:17 pm
Location: Quito - Ecuador

Re: TWebView y Javascript

Post 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.
Saludos
_
Fwh 10.4, bcc55
User avatar
cnavarro
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: TWebView y Javascript

Post 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
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
User avatar
Antonio Linares
Site Admin
Posts: 42270
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: TWebView y Javascript

Post 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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
EASYSOFT
Posts: 190
Joined: Sat Oct 22, 2005 1:17 pm
Location: Quito - Ecuador

Re: TWebView y Javascript

Post by EASYSOFT »

Cristóbal , Antonio
Muchas gracias seguire investigando

Saludos
Saludos
_
Fwh 10.4, bcc55
Post Reply