How to get Anchor from an Element of a document

Posted on

Sub myFunction(Url,Info)
On Error Resume Next
set myObj=CreateObject(“myATL.UrlSetter.1″)
if err0 then
MsgBox(“myObj not properly installed"+ vbCrLf+"Please install myObj again")
else
myObj.SetURL2(Url)
end if
end sub

Sub OnContextMenu()

set srcEvent = external.menuArguments.event
set EventElement = external.menuArguments.document.elementFromPoint ( srcEvent.clientX, srcEvent.clientY )
if srcEvent.type = “MenuExtAnchor" then

set srcAnchor = EventElement
do until TypeName(srcAnchor)="HTMLAnchorElement"
set srcAnchor=srcAnchor.parentElement
Loop
Call myFunction(srcAnchor.href,srcAnchor.innerText)
elseif srcEvent.type="MenuExtImage" then

if TypeName(EventElement)="HTMLAreaElement" then
Call myFunction(EventElement.href,EventElement.Alt)
else
set srcImage = EventElement
set srcAnchor = srcImage.parentElement
do until TypeName(srcAnchor)="HTMLAnchorElement"
set srcAnchor=srcAnchor.parentElement
if TypeName(srcAnchor)="Nothing" then
call myFunction(srcImage.href,srcImage.Alt)
exit sub
end if
Loop
Call myFunction(srcAnchor.href,srcImage.Alt)
end if
elseif srcEvent.type="MenuExtUnknown" then

set srcAnchor = EventElement
do until TypeName(srcAnchor)="HTMLAnchorElement"
set srcAnchor=srcAnchor.parentElement
if TypeName(srcAnchor)="Nothing" then
Call myFunction(EventElement.href,EventElement.innerText)
exit sub
end if
Loop
Call myFunction(srcAnchor.href,srcAnchor.innerText)
elseif 1=1 then
MsgBox(“Unknown Event Source “"" + srcEvent.type + “""" + vbCrLf + “")
end if
end sub

call OnContextMenu()

廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s