2016-12-07 1 views
0

이미지와 관련된 링크가 필요합니다. 아래 코드에서 알 수 있듯이 TWebBrowser 구성 요소가 사용자 정의되어 있습니다. WebBrowser보기에서 마우스 클릭을 가로 챌 것입니다.TWebBrowser : 링크가있는 이미지를 클릭하면 링크 href가 표시됩니다.

현재 코드는 일반적인 링크에서 잘 작동하지만 이미지의 경우 이미지를 클릭 할 때 href 링크를 가져올 수 없습니다. 내가 이미지를 클릭하면

, 나는 "https://vimeo.com/194387045을"= 링크 HREF를 얻을 내가 갈 수

다른 방법이?

<p>&nbsp;</p> 
<p><a href="https://vimeo.com/194387045" target="_blank"> 
<img src="http://172.16.0.16/static/comunica/436dde8236d078cff2dc76deaa113dbb" 
alt="" /></a></p> 

방법 :

Procedure TJBWebBrowser.ValidateLinkClick; 
Var 
    LElement: IHTMLElement; 
    LLink, LTag: String; 
    LCancel: Boolean; 
    LDocument: IHTMLDocument2; 
Begin 

    LDocument := IHTMLDocument2(Document); 

    If Not Assigned(LDocument) Then 
    Exit; 

    LCancel := False; 
    LElement := LDocument.parentWindow.event.srcElement; 
    LTag := Trim(LowerCase(LElemento.tagName)); 

    If LTag = 'a' Then 
    LLink := Trim(LElement.getAttribute('href', 0)); 

    If Assigned(FOnURLClick) Then 
    FOnURLClick(Self, LLink, LCancel); 

    If (LLink <> EmptyStr) And (Not LCancel) Then 
    ShellExecute(0, Nil, PChar(LLink), Nil, Nil, SW_SHOWNORMAL); 
End; 

답변

0

나는 나의 의심에 대한 해결책을 발견했다.

모두에게 감사드립니다.

변경된 코드에 따라 : 그래서

Procedure TJBWebBrowser.ValidateLinkClick; 
Var 
    LElement: IHTMLElement; 
    LLink, LTag: String; 
    LCancel: Boolean; 
    LDocument: IHTMLDocument2; 
Begin 

    LCancel := False; 
    LDocument := IHTMLDocument2(Document); 

    If Not Assigned(LDocument) Then 
    Exit; 

    //Old line 
    //LElement := LDocument.parentWindow.event.srcElement; 

    //New line 
    LElement := LDocument.activeElement; 
    if not Assigned(LElement) then 
    Exit; 

    LTag := Trim(LowerCase(LElement.tagName)); 

    If LTag = 'a' Then 
    LLink := Trim(LElement.getAttribute('href', 0)); 

    If Assigned(FOnURLClick) Then 
    FOnURLClick(Self, LLink, LCancel); 

    If (LLink <> EmptyStr) And (Not LCancel) Then 
    ShellExecute(0, Nil, PChar(LLink), Nil, Nil, SW_SHOWNORMAL); 
End; 
관련 문제