WebView window

Natter
Posts: 1226
Joined: Mon May 14, 2007 9:49 am

WebView window

Post by Natter »

Hi,

The window of the WebView object creates a window. Is it possible to make the WebView open in a hidden form (without a window appearing on the screen) ?
User avatar
Antonio Linares
Site Admin
Posts: 42268
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: WebView window

Post by Antonio Linares »

You can make it children of another window so it will behave as a control

Or do you want it totally hidden ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1226
Joined: Mon May 14, 2007 9:49 am

Re: WebView window

Post by Natter »

That's what I do. But this does not solve the problem of the window appearing (at least for 1 second) when creating a WebView
User avatar
Jimmy
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: WebView window

Post by Jimmy »

hi,

you can use "negative" Position at "Create" and later "move" to new Position / Parent
greeting,
Jimmy
User avatar
Antonio Linares
Site Admin
Posts: 42268
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: WebView window

Post by Antonio Linares »

Dear Jimmy,

He won't be able to do that as WebView_Create() called from TWebView():New() does not allow the use of coordinates

Maybe this may work:
#define SW_HIDE 0
#define SW_NORMAL 1

local oWebView := TWebView():New()

ShowWindow( oWebView:GetWindow(), SW_HIDE )
... then do the required startup code and finally:
ShowWindow( oWebView:GetWindow(), SW_NORMAL )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1226
Joined: Mon May 14, 2007 9:49 am

Re: WebView window

Post by Natter »

Trying to execute this program:

Code: Select all | Expand

#include "FiveWin.ch"

function Main()
local oWebKds := TWebView():New()

    oWebKds := TWebView():New()

    oWebKds:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
    oWebKds:Bind( "SendKds" )


    cUrl:="https://www.google.com"
    buf:='function Kds_Url() { SendKds(document.body.innerHTML) } ;'+CRLF+ ;
         'window.location.href="'+cUrl+'" ;'+CRLF+ ;
         'Kds_Url() ;'

    DEFINE DIALOG oKds FROM 0,0 TO 400,400  PIXEL ;
       STYLE nOR(WS_POPUP)  COLOR CLR_BLACK, CLR_WHITE
    ACTIVATE DIALOG oKds  ON PAINT (oWebKds:SetParent(oKds), oWebKds:Eval(buf))
return
The code block :bOnBind does not work. What am I doing wrong ?
User avatar
Antonio Linares
Site Admin
Posts: 42268
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: WebView window

Post by Antonio Linares »

This works fine:

Code: Select all | Expand

#include "FiveWin.ch"

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

function Main()

   local oWebView := TWebView():New()

   oWebView:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
   oWebView:Bind( "SendToFWH" )
   oWebView:Navigate( Html() )
   Sleep( 200 )
   oWebView:Run()
   oWebView:Destroy()

return nil

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

function Html()

   local cHtml

   TEXT INTO cHtml
      data:text/html,
      <html>
         <head>
         </head>
         <body style="background-color:cyan">
            <h2>Using WebView from FWH</h2>
            <button onclick='SendToFWH( 123 )'>Call FWH app from web browser</button>
            <button onclick='SendToFWH( 456 )'>Test 2</button>
            <button onclick='SendToFWH( document.body.innerHTML )'>Test 3</button>
         </body>
      </html>
   ENDTEXT      

return cHtml

//----------------------------------------------------------------------------//
Are trying to add javascript code to an exiting web site ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42268
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: WebView window

Post by Antonio Linares »

Another example using Class TWebView Method Eval():

Code: Select all | Expand

#include "FiveWin.ch"

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

function Main()

   local oWebView := TWebView():New()

   oWebView:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
   oWebView:Bind( "SendToFWH" )
   oWebView:Navigate( Html() )
   Sleep( 200 )
   oWebView:Eval( "SendToFWH( document.body.innerHTML )" )
   oWebView:Run()
   oWebView:Destroy()

return nil

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

function Html()

   local cHtml

   TEXT INTO cHtml
      data:text/html,
      <html>
         <head>
         </head>
         <body style="background-color:cyan">
            <h2>Using WebView from FWH</h2>
            <button onclick='SendToFWH( 123 )'>Call FWH app from web browser</button>
            <button onclick='SendToFWH( 456 )'>Test 2</button>
            <button onclick='SendToFWH( document.body.innerHTML )'>Test 3</button>
         </body>
      </html>
   ENDTEXT      

return cHtml

//----------------------------------------------------------------------------//
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1226
Joined: Mon May 14, 2007 9:49 am

Re: WebView window

Post by Natter »

Yes, I need to make frequent site requests and read the changes. This is a very convenient algorithm for me and I do not understand why in this case the code block :bonBind does not work :cry:

the oWebKds:SetParent() method works, but the oWebKds:Eval() method does not
User avatar
Antonio Linares
Site Admin
Posts: 42268
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: WebView window

Post by Antonio Linares »

This is working fine:

Code: Select all | Expand

#include "FiveWin.ch"

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

function Main()

   local oWebView := TWebView():New()

   oWebView:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
   oWebView:Bind( "SendToFWH" )
   oWebView:Navigate( "https://www.fivetechsoft.com" )
   Sleep( 200 )
   oWebView:Eval( "SendToFWH( document.body.innerHTML )" )
   oWebView:Run()
   oWebView:Destroy()

return nil

//----------------------------------------------------------------------------//
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
cnavarro
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: WebView window

Post by cnavarro »

Try with

Code: Select all | Expand

    ACTIVATE DIALOG oKds ON INIT ( oWebKds:SetParent(oKds), Sleep( 300 ) ) ON PAINT ( oWebKds:Eval(buf) )
 
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
Natter
Posts: 1226
Joined: Mon May 14, 2007 9:49 am

Re: WebView window

Post by Natter »

I checked, nothing has changed :(
User avatar
cnavarro
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: WebView window

Post by cnavarro »

Consider the following:
- The change in the content of the oWebView control does not cause the Paint event of the dialog to be executed
- In your javascript code, you are causing a recursive call to the same function.
I want to check that your code ( Eval() ) is executed? ( assuming there is no error in that code )
Change your code and resize dialog

Code: Select all | Expand

 DEFINE DIALOG oDlg FROM 0,0 TO 400,400  PIXEL TRUEPIXEL RESIZABLE
 
If you want that function defined in ON PAINT to be executed, one of the possible options is to use a TIMER
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
Natter
Posts: 1226
Joined: Mon May 14, 2007 9:49 am

Re: WebView window

Post by Natter »

I tried to write like this:

Code: Select all | Expand

#include "FiveWin.ch"

function Main()
local oWebKds := TWebView():New()

    oWebKds := TWebView():New()

    oWebKds:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
    oWebKds:Bind( "SendKds" )

   cUrl:="https://www.google.com"
    buf:='function Kds_Url() { SendKds(document.body.innerHTML) } ;'+CRLF+ ;
         'window.location.href="'+cUrl+'" ;'+CRLF+ ;
         'document.addEventListener("DOMContentLoaded", Kds_Url()) ;'

    DEFINE DIALOG oKds FROM 0,0 TO 400,400  PIXEL TRUEPIXEL RESIZABLE TITLE "Test"
    ACTIVATE DIALOG oKds  ON PAINT (sleep(200), oWebKds:Eval(buf))
return
 
Three :shock: windows appear:
1-DIALOG "Test"
2-webview with GOOGLE.COM
3-webview is empty
User avatar
Antonio Linares
Site Admin
Posts: 42268
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: WebView window

Post by Antonio Linares »

You are calling TWebView():New() twice

why ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply