HTML with JavaScript

Buenos das a todos!
Estoy implementando un previsualizador de documentos con HTMLviewer en Xojo Web. El mismo hace uso de un archivo Javascript para poder colocarle un cdigo QR al documento. El problema es que no se est ejecutando la funcin js y no se puede ver la imagen del QR.
Alguien sabe cmo podra solucionarlo?
Desde ya muchas gracias!

Just a detail: to post in Spanish, better use the International/Espanol channel.

Here is the translation of your post:

[quote]
Good morning to everybody!
I am implementing a document previewer with HTMLviewer in Xojo Web. It makes use of a Javascript file to be able to put a QR code on the document. The problem is that the js function is not running and the QR image cannot be seen.
Does anyone know how I could fix it?
From already thank you very much![/quote]

Technically, WebHTMLViewer, contrary to desktop HTMLViewer, is not standalone control. It is in fact underneath an iFrame, part of the app’s entire HTML.

Chances are the Javascript assumes it is running in the DOM, and makes reference to document in a way that does not take into account that it is, in fact, running within an iFrame.

Your best bet would be to build an HTML page, and actually send to the default browser instead, with ShowURL http://documentation.xojo.com/api/deprecated/showurl.html .

Thanks Michel.
I don’t know how to do that… I read the Documentation and I think that doesn’t work. I show you what I will do.
I have this HTML document:

[code]

body {
margin: 0mm 9mm 6mm;
}

"2020 - Año del General Manuel Belgrano"

CONSTANCIA DE INSCRIPCIÓN A LLAMADO ABIERTO

Se certifica que el Sr/Sra. colocar nombre, DNI: colocar dni, CUIL: colocar cuil se ha inscripto al llamado abierto con fecha colocar llamado para el/los cargo/s de colocar cargos mediante la plataforma ABIERTOS autorizada mediante resoluci&oacuten N°123/45 del Ministerio De Educación de la Provincia de Santiago del Estero.

Santiago del Estero, fecha de hoy .   

El QR va aquí

           Firma de Autoridades de Mesa:

 

 

 

 

_____________________________

Firma del Optante

colocar nombre

CUIL: colocar cuil

   

 

 

 

 

 

 

 

 

 

 

 

[/code]

It uses qrcode.js that is another file.
That i will show in a HTMLViewer… but the js doesn’t execute. The browser shows me an error Message.
I try do that with your advise and stills the same…
Thanks to your answer. And sorry for my bad english.

What is the error message that you’re receiving from the browser? Your JS code is fine after running it through Closure Compiler, so I don’t think the issue is there.

Incidentally, if you want to bypass working with JavaScript, I offer GraffitiWebQR for QR code generation.

Thanks Anthony.
It shows me this error: “Could not execute returned javascript: Unable to set property ‘innerHTML’ of undefined or null reference”.
And I try this but stills happening:

[code]Dim script As String
script=“var typeNumber = 0;”+_
“var errorCorrectionLevel = ‘L’;”+_
“var qr = qrcode(typeNumber, errorCorrectionLevel);”+_
“qr.addData(’ Se certifica que el Sr/Sra. colocar nombre, DNI: colocar dni, CUIL: colocar cuil se ha inscripto al llamado abierto con fecha colocar llamado para el/los cargo/s de colocar cargos mediante la plataforma ABIERTOS autorizada mediante resoluci&oacuten N°123/45 del Ministerio De Educación de la Provincia de Santiago del Estero.’);”+_
“qr.make();”+_
“document.getElementById(‘Documento’).innerHTML = qr.createImgTag(1,1);”

Dim qr As String
qr=qrcode
VistaPC.CCPrevisualizadorPC1.HVConstancia.ExecuteJavaScript(qr)
VistaPC.CCPrevisualizadorPC1.HVConstancia.ExecuteJavaScript(script)
VistaPC.CCPrevisualizadorPC1.HVConstancia.LoadPage(cadenaHTML)[/code]

It’s likely that your JavaScript code is executing before the element is loaded in the browser. That error is telling you that your Documento DIV doesn’t exist in the DOM.

I found this with the CkEditor code I set up. Is there any guidance on how long it takes for an HTMLViewer to load?

I set a single Timer for 5 seconds before I sent the JavaScript, but is there a better way?

Don’t use a timer. Use DOM events.

Hi!
I still having the same error… I read all the documentation about DOM and now i am trying to do this:

Dim script As String
script="var typeNumber = 0;"+_
"var division=document.createElement('div');"+_
"var contenido=document.createTextNode('Documento');"+_
"division.appendChild(contenido);"+_
"var errorCorrectionLevel = 'L';"+_
"var qr = qrcode(typeNumber, errorCorrectionLevel);"+_
"qr.addData(""Se certifica que el Sr/Sra. colocar nombre, DNI: colocar dni, CUIL: colocar cuil se ha inscripto al llamado abierto con fecha colocar llamado para el/los cargo/s de colocar cargos mediante la plataforma ABIERTOS autorizada mediante resoluci&oacuten N°123/45 del Ministerio De Educación de la Provincia de Santiago del Estero."");"+_
"qr.make();"+_
"var objeto=  document.querySelector('#Documento); "+_
"alert(objeto);"
VistaPC.CCPrevisualizadorPC1.HVConstancia.ExecuteJavaScript(qr)
VistaPC.CCPrevisualizadorPC1.HVConstancia.ExecuteJavaScript(script)
VistaPC.CCPrevisualizadorPC1.HVConstancia.LoadPage(cadenaHTML)

But now… the browser returns me null when i try to get ‘Documento’ . I don’t know what i’m doing bad…
I try too, putting all the executejavascript in another Buttom but doesn’t work…
I think that Anthony have reason… but i don’t know how to force that the html and the object ‘documento’ loades before execute Javascript.

This is your best option:

https://graffitisuite.com/features/web-edition/graffitiwebqr/

Hi,
You should look at the examples in the “Extras ->WebSDK->Examples” folder to see how the WebControlWrapper class works. There are special events to generate the DOM in HTML by assigning for example a specific div id of xojo

.Execute javascript by entering the command “Xojo.triggerServerEvent(’”+me.controlID+"’, ‘NameEventXojo’, [result]); "which will return the value in the ExecuteEvent event and then decide how to manage it in xojo. Otherwise if you want to manage everything from javascript remember to assign the unique id. Because if you have multiple instances of the same WebControlWrapper object you must be able to distinguish which one you are working on.

[quote=479972:@Mariel Alejandra Caro]Hi!

I think that Anthony have reason… but i don’t know how to force that the html and the object ‘documento’ loades before execute Javascript.[/quote]

This javascript you should put into a function like this:

<script type="text/javascript"> function startup () { var typeNumber = 0; var errorCorrectionLevel = 'L'; var qr = qrcode(typeNumber, errorCorrectionLevel); qr.addData(' Se certifica que el Sr/Sra. colocar nombre, DNI: colocar dni, CUIL: colocar cuil se ha inscripto al llamado abierto con fecha colocar llamado para el/los cargo/s de colocar cargos mediante la plataforma ABIERTOS autorizada mediante resoluci&oacuten N°123/45 del Ministerio De Educaci&oacute;n de la Provincia de Santiago del Estero.'); qr.make(); document.getElementById('Documento').innerHTML = qr.createImgTag(1,1); } </script>

Then you change <body> to be <body onload="startup();"> which will cause the javascript to be run after the document is loaded.

Thanks Tim!!! I used a similar solution. I read your answer after I made it work.
I put here if someone else need:

"<script type=""text/javascript"">function load() {"+_ "var typeNumber = 0;"+_ "var errorCorrectionLevel = 'L';"+_ "var qr = qrcode(typeNumber, errorCorrectionLevel);"+_ "qr.addData(""Se certifica que el Sr/Sra. colocar nombre, DNI: colocar dni, CUIL: colocar cuil se ha inscripto al llamado abierto con fecha colocar llamado para el/los cargo/s de colocar cargos mediante la plataforma ABIERTOS autorizada mediante resolucin N123/45 del Ministerio De Educacin de la Provincia de Santiago del Estero."");"+_ "qr.make();"+_ "document.getElementById(""Mariel"").innerHTML = qr.createImgTag(1,1); "+_ "}"+_ "document.addEventListener('DOMContentLoaded', load());"+_ "</script>"+_ "</body></html>"
Thanks a lot for all that help me!