FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Questions about WebView
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Questions about WebView
Posted: Wed Nov 23, 2022 01:12 PM

Hi,

  1. In IE I can get the web page document so oIE:GetProp("Document"). Can I do this in WebView ?

2/ There is a Navigate method in the WebView class. Is it possible to use it to download HTML text from a file ?

  1. When I launch WebView, a standard window opens. Is it possible to change its type to PopUp ?

  2. Is it possible to embed this window in a window with an FW application (in the specified coordinates) ?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Questions about WebView
Posted: Wed Nov 23, 2022 03:41 PM
Dear Yuri,

Please try this:

1.
Code (fw): Select all Collapse
function Main()

   local oWebView := TWebView():New(), aaa

   oWebView:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
   oWebView:Bind( "SendToFWH" )
   oWebView:Navigate( "https://your_url.com" )
   Sleep( 200 )
   oWebView:Eval( 'window.onload = function () { SendToFWH( document ) }' )
   oWebView:Run()
   oWebView:Destroy()

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Questions about WebView
Posted: Wed Nov 23, 2022 03:44 PM
  1. Simply use this code in your HTML:

<a href="test.txt" download>Click here</a>

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Questions about WebView
Posted: Wed Nov 23, 2022 03:46 PM
3 and 4.:

Class TWebView provides a Method SetParent( oWnd ) so you can make it child of any window, dialog or control :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Questions about WebView
Posted: Wed Nov 23, 2022 05:03 PM

Thank you, Antonio! Good answer. I'll try to use it tomorrow.

Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Questions about WebView
Posted: Thu Nov 24, 2022 09:00 AM

In I create a WebView and in the script I open a new page

var pdg= new URL('MyPage') ;

I need to return some data to the FW on the page URL change event. How can I do this?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Questions about WebView
Posted: Thu Nov 24, 2022 10:11 AM
Dear Yuri,

When you use this code:
http://fivetechsupport.com/forums/viewtopic.php?p=255632&sid=1d500740664e0671278e8d3f3076d61a#p255632
you can call SendToFWH( params... ) from the web HTML javascript and your FWH app will get it on the oWebView:bOnBind codeblock
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Questions about WebView
Posted: Thu Nov 24, 2022 10:57 AM

**

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Questions about WebView
Posted: Thu Nov 24, 2022 01:52 PM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Questions about WebView
Posted: Thu Nov 24, 2022 02:15 PM
  1. Is it possible to ask for an example script in the method :Eval() of several lines

  2. Why the method is needed :setHtml if you can't write a JS script in it ?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Questions about WebView
Posted: Thu Nov 24, 2022 06:32 PM

Dear Yuri,

> 1. Is it possible to ask for an example script in the method :Eval() of several lines

Call a function from inside the codeblock where you can easily use multiple lines of code

> 2. Why the method is needed :setHtml if you can't write a JS script in it ?

Of course that you can use JS script in the cHtml that you provide to Method SetHtml(). I am going to provide you an example

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Questions about WebView
Posted: Thu Nov 24, 2022 06:36 PM
webview2.prg working fine here
Code (fw): Select all Collapse
// Please install https://developer.microsoft.com/en-us/microsoft-edge/webview2/ x86 version before using it

#include "FiveWin.ch"

function Main()

   local oWebView := TWebView():New()

   oWebView:SetHtml( Html() )
   oWebView:SetTitle( "Microsoft Edge WebView working from FWH" )
   oWebView:SetSize( 1200, 800 )
   oWebView:SetUserAgent( "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Mobile Safari/537.36" )
   sleep( 300 )
   oWebView:Run()
   oWebView:Destroy()

return nil

function Html()

   local cHtml

   TEXT INTO cHtml
   <!DOCTYPE html>
   <html>
   <body>
   
   <h1>The Window Object</h1>
   <h2>The alert() Method</h2>
   
   <p>Click the button to display an alert box.</p>
   
   <button onclick="myFunction()">Try it</button>
   
   <script>
   function myFunction() {
     alert("Hello! I am an alert box!");
   }
   </script>
   
   </body>
   </html>
   ENDTEXT

return cHtml
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Questions about WebView
Posted: Fri Nov 25, 2022 07:16 AM
A good example !
What is the method for :oWebView:SetUserAgent(), the program also works without it ?
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Questions about WebView
Posted: Fri Nov 25, 2022 07:17 AM

Dear Yuri,

Method SetUserAgent() is a workaround to be able to login into your goggle account.

Without it you can't login into gmail, etc

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Questions about WebView
Posted: Fri Nov 25, 2022 08:39 AM
Can I use WebView to do the following:
a) Open a page
b) find an item on this page
c) click on this item

All this is easy to do via IE (Activex), but it does not work on WebView :(