TWebView y Javascript

TWebView y Javascript

Postby EASYSOFT » Thu Jul 13, 2023 7: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 10.4, bcc55
EASYSOFT
 
Posts: 185
Joined: Sat Oct 22, 2005 1:17 pm
Location: Quito - Ecuador

Re: TWebView y Javascript

Postby leandro » Fri Jul 14, 2023 12:32 am

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) ]
User avatar
leandro
 
Posts: 1676
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: TWebView y Javascript

Postby EASYSOFT » Fri Jul 14, 2023 6:33 pm

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

Re: TWebView y Javascript

Postby EASYSOFT » Sun Jul 16, 2023 8: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 10.4, bcc55
EASYSOFT
 
Posts: 185
Joined: Sat Oct 22, 2005 1:17 pm
Location: Quito - Ecuador

Re: TWebView y Javascript

Postby cnavarro » 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
User avatar
cnavarro
 
Posts: 6548
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: TWebView y Javascript

Postby Antonio Linares » Mon Jul 17, 2023 7: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: TWebView y Javascript

Postby EASYSOFT » Mon Jul 17, 2023 3:03 pm

Cristóbal , Antonio
Muchas gracias seguire investigando

Saludos
Saludos
Oscar
Fwh 10.4, bcc55
EASYSOFT
 
Posts: 185
Joined: Sat Oct 22, 2005 1:17 pm
Location: Quito - Ecuador


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 35 guests