Questions about WebView

Questions about WebView

Postby Natter » Wed Nov 23, 2022 1: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 ?
3. When I launch WebView, a standard window opens. Is it possible to change its type to PopUp ?
4. Is it possible to embed this window in a window with an FW application (in the specified coordinates) ?
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Questions about WebView

Postby Antonio Linares » Wed Nov 23, 2022 3:41 pm

Dear Yuri,

Please try this:

1.
Code: Select all  Expand view
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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Questions about WebView

Postby Antonio Linares » Wed Nov 23, 2022 3:44 pm

2. Simply use this code in your HTML:

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

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

Re: Questions about WebView

Postby Antonio Linares » Wed Nov 23, 2022 3: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Questions about WebView

Postby Natter » Wed Nov 23, 2022 5:03 pm

Thank you, Antonio! Good answer. I'll try to use it tomorrow.
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Questions about WebView

Postby Natter » Thu Nov 24, 2022 9: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?
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Questions about WebView

Postby Antonio Linares » Thu Nov 24, 2022 10:11 am

Dear Yuri,

When you use this code:
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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Questions about WebView

Postby Natter » Thu Nov 24, 2022 10:57 am

**
Last edited by Natter on Thu Nov 24, 2022 2:14 pm, edited 2 times in total.
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Questions about WebView

Postby Antonio Linares » Thu Nov 24, 2022 1:52 pm

regards, saludos

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

Re: Questions about WebView

Postby Natter » Thu Nov 24, 2022 2: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 ?
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Questions about WebView

Postby Antonio Linares » Thu Nov 24, 2022 6: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Questions about WebView

Postby Antonio Linares » Thu Nov 24, 2022 6:36 pm

webview2.prg working fine here

Code: Select all  Expand view
// Please install https://developer.microsoft.com/en-us/m ... /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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Questions about WebView

Postby Natter » Fri Nov 25, 2022 7:16 am

A good example !
What is the method for :oWebView:SetUserAgent(), the program also works without it ?
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Questions about WebView

Postby Antonio Linares » Fri Nov 25, 2022 7: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Questions about WebView

Postby Natter » Fri Nov 25, 2022 8: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 :(
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 71 guests

cron