FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour WebView window
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
WebView window
Posted: Sun Dec 25, 2022 07:26 PM

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) ?

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: WebView window
Posted: Sun Dec 25, 2022 09:35 PM

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
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: WebView window
Posted: Mon Dec 26, 2022 07:01 AM

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

Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: WebView window
Posted: Mon Dec 26, 2022 07:23 AM

hi,

you can use "negative" Position at "Create" and later "move" to new Position / Parent

greeting,

Jimmy
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: WebView window
Posted: Mon Dec 26, 2022 07:41 AM

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
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: WebView window
Posted: Mon Dec 26, 2022 12:41 PM
Trying to execute this program:
Code (fw): Select all Collapse
#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 ?
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: WebView window
Posted: Mon Dec 26, 2022 04:03 PM
This works fine:
Code (fw): Select all Collapse
#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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: WebView window
Posted: Mon Dec 26, 2022 04:15 PM
Another example using Class TWebView Method Eval():
Code (fw): Select all Collapse
#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
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: WebView window
Posted: Mon Dec 26, 2022 04:36 PM
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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: WebView window
Posted: Mon Dec 26, 2022 05:22 PM
This is working fine:
Code (fw): Select all Collapse
#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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: WebView window
Posted: Mon Dec 26, 2022 05:36 PM
Try with
Code (fw): Select all Collapse
    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
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: WebView window
Posted: Mon Dec 26, 2022 05:59 PM
I checked, nothing has changed :(
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: WebView window
Posted: Mon Dec 26, 2022 06:15 PM
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 (fw): Select all Collapse
 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
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: WebView window
Posted: Mon Dec 26, 2022 07:08 PM
I tried to write like this:
Code (fw): Select all Collapse
#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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: WebView window
Posted: Mon Dec 26, 2022 07:20 PM

You are calling TWebView():New() twice

why ?

regards, saludos

Antonio Linares
www.fivetechsoft.com