Jump to content
Juan Young

[WebBrowser] how to get url on click a href in TWebbrowser

Recommended Posts

I have apps with TWebbrowser.loadstrings and there is many a href link but if i click that link webbrowser navigate that link.. 

 

How can i get that link on event on click / on tab or something ? i see event on TWebbrowser is not exist..

Share this post


Link to post
4 hours ago, Juan Young said:

i'm already try.. not work... onShouldStartLoadWithRequest is not fire anything

Clicking on a hyperlink starts a load request.  You should be getting events for that.

 

Lets starts with the obvious - did you actually ASSIGN a handler to that event?

4 hours ago, Juan Young said:

OnDidStartLoad  = will start all link embeded on that html... so confuse..

I'm confused.  What are you trying to say exactly?  Can you provide a ste-by-step example?

Share this post


Link to post
5 hours ago, Remy Lebeau said:

Clicking on a hyperlink starts a load request.  You should be getting events for that.

 

Lets starts with the obvious - did you actually ASSIGN a handler to that event?

I'm confused.  What are you trying to say exactly?  Can you provide a ste-by-step example?

 

    tags := tstringlist.Create;
    tags.Add(dataweb);
    tags.SaveToFile(System.IOUtils.TPath.GetDocumentsPath + PathDelim + 'DataTampilan.html');
    if FileExists(System.IOUtils.TPath.GetDocumentsPath + PathDelim + 'DataTampilan.html') then
    begin
       tags.LoadFromFile(System.IOUtils.TPath.GetDocumentsPath + PathDelim + 'DataTampilan.html');
    end;
    tags.Free;

    wb1.URL:=System.IOUtils.TPath.GetDocumentsPath + PathDelim + 'DataTampilan.html';
    wb1.Navigate;

    

like that.. and in at DataTampilan.html have lot link A Href... how i can catch if i click that link because if i OnDidStartLoad on that wb1 it will catch 5 times as sum as a href

 

 

test.png

 

if i click that url on right WB1 is not fire test on debug view >,,<

Edited by Juan Young
add image

Share this post


Link to post
12 hours ago, Juan Young said:

in at DataTampilan.html have lot link A Href... how i can catch if i click that link

I already told you how.  Clicking on a hyperlink inside the HTML is supposed to fire the OnShouldStartLoadWithRequest and OnDidStartLoad events.  If it is not, then you should file a bug report.

12 hours ago, Juan Young said:

because if i OnDidStartLoad on that wb1 it will catch 5 times as sum as a href

I don't understand what you are describing, but that doesn't seem to match with your screenshot.

12 hours ago, Juan Young said:

if i click that url on right WB1 is not fire test on debug view >,,<

Are you running your code in the IDE's debugger? If so, the messages will go to the debugger's output window, not to DebugView.

Share this post


Link to post
On 4/21/2020 at 12:32 PM, Juan Young said:

 


    tags := tstringlist.Create;
    tags.Add(dataweb);
    tags.SaveToFile(System.IOUtils.TPath.GetDocumentsPath + PathDelim + 'DataTampilan.html');
    if FileExists(System.IOUtils.TPath.GetDocumentsPath + PathDelim + 'DataTampilan.html') then
    begin
       tags.LoadFromFile(System.IOUtils.TPath.GetDocumentsPath + PathDelim + 'DataTampilan.html');
    end;
    tags.Free;

    wb1.URL:=System.IOUtils.TPath.GetDocumentsPath + PathDelim + 'DataTampilan.html';
    wb1.Navigate;

    

like that.. and in at DataTampilan.html have lot link A Href... how i can catch if i click that link because if i OnDidStartLoad on that wb1 it will catch 5 times as sum as a href

 

 

test.png

 

if i click that url on right WB1 is not fire test on debug view >,,<

Hi, I'm using this code :

 

procedure Tfrm_isi.WebBrowser1DidStartLoad(ASender: TObject);
var url : string;
begin
  url := WebBrowser1.URL;
  if url<>'about:blank' then
  begin

   //do here

  end;

end;

 

regards,

Ipay

Share this post


Link to post
On 10/14/2020 at 9:16 PM, ipay said:

Hi, I'm using this code :

 

procedure Tfrm_isi.WebBrowser1DidStartLoad(ASender: TObject);
var url : string;
begin
  url := WebBrowser1.URL;
  if url<>'about:blank' then
  begin

   //do here

  end;

end;

 

regards,

Ipay

hi ipay

 

that event didn't fire >,<

 

 

regard

Share this post


Link to post
1 hour ago, Juan Young said:

that event didn't fire

It won't fire if it cannot. OnShouldStartLoadWithRequest should fire for every URL that is visited. As Remy said, if it does not, then there's a bug.

Share this post


Link to post
19 hours ago, Dave Nottage said:

It won't fire if it cannot. OnShouldStartLoadWithRequest should fire for every URL that is visited. As Remy said, if it does not, then there's a bug.

hi,

 

i tried code like below and i open Debugview.. didn't fire anything too.. >,<..

procedure TFrameTampilanData.WB1ShouldStartLoadWithRequest(ASender: TObject;
  const URL: string);
begin
  outputdebugstring(PwideChar(URL));
end;

 

regard

 

 

Share this post


Link to post
2 hours ago, Juan Young said:

i tried code like below and i open Debugview.. didn't fire anything too.. >,<..

Odd.  Are you ABSOLUTELY SURE that those event handlers are actually assigned to the TWebBrowser?

Share this post


Link to post
3 hours ago, Juan Young said:

i tried code like below and i open Debugview

Running it from the IDE, or standalone? If you run it from the IDE, the messages appear in the Messages window of the IDE

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×