Jump to content
Sign in to follow this  
soulhealer

Intercepting IE Link clicked on an IE object

Recommended Posts

soulhealer

hi, is there a way intercept a clicked link on IE object? i mean, capture the link that is clicked on IE object(IE Window) instead of being navigated to that link.

thanks for any help.

Share this post


Link to post
Share on other sites
DaleHohm

It needs to be done on the client-side since AutoIt gets informed of events asynchronously.

See _IEHeadInsertEventScript

Assume the link you want to affect is the 5th link on the page (index 4). The "return false;" aborts the event logic before the navigation occurs:

$oIE = _IECreate(your-url)
$oLink = _IELinkGetCollection($oIE, 4)
$sLinkId = $oLink.uniqueId
_IEHeadInsertEventScript($oIE, $sLinkId, "onclick", "alert('Someone clicked the Link!');return false;")

Dale

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
soulhealer

It needs to be done on the client-side since AutoIt gets informed of events asynchronously.

See _IEHeadInsertEventScript

Assume the link you want to affect is the 5th link on the page (index 4). The "return false;" aborts the event logic before the navigation occurs:

$oIE = _IECreate(your-url)
$oLink = _IELinkGetCollection($oIE, 4)
$sLinkId = $oLink.uniqueId
_IEHeadInsertEventScript($oIE, $sLinkId, "onclick", "alert('Someone clicked the Link!');return false;")

Dale

Dale

cool, but what if i want to intercept every link on the page, i don't know what the links are, but i wish to capture the link(URL) whenever i click one of them(without navigating to that link).

edit: when u mention 'client-side', u meant that the event response is on the page, not in auto-it process anymore, so there is no way that the link will be captured to auto-it process? except through clipboard i guess, but i dunno javascript, what is the function to put a string on to clipboard? something like ClipPut($string) on auto-it.

Edited by soulhealer

Share this post


Link to post
Share on other sites
DaleHohm

Interesting query... here you go:

#include <IE.au3>

$oIE = _IECreate("http://www.google.com")
$oLinks = _IELinkGetCollection($oIE)
For $oLink in $oLinks
    $sLinkId = $oLink.uniqueId
    _IEHeadInsertEventScript($oIE, $sLinkId, "onclick", "return false;")
    ObjEvent($oLink, "_Evt_")
Next

While 1
    Sleep(100)
WEnd

Func _Evt_onclick()
    Local $o_link = @COM_EventObj
    ConsoleWrite($o_link.href & @CR)
EndFunc

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
soulhealer

Interesting query... here you go:

#include <IE.au3>

$oIE = _IECreate("http://www.google.com")
$oLinks = _IELinkGetCollection($oIE)
For $oLink in $oLinks
    $sLinkId = $oLink.uniqueId
    _IEHeadInsertEventScript($oIE, $sLinkId, "onclick", "return false;")
    ObjEvent($oLink, "_Evt_")
Next

While 1
    Sleep(100)
WEnd

Func _Evt_onclick()
    Local $o_link = @COM_EventObj
    ConsoleWrite($o_link.href & @CR)
EndFunc

Dale

ow great, i'm getting to understand about it, this function insert javascript on to the page, but what if i need to remove it(them) again? also do u know what is the ClipPut(value) on javascript? i have an idea how to get value from javascript back to auto-it through the clipboard memory. Edited by soulhealer

Share this post


Link to post
Share on other sites
DaleHohm

ow great, i'm getting to understand about it, this function insert javascript on to the page, but what if i need to remove it(them) again? also do u know what is the ClipPut(value) on javascript? i have an idea how to get value from javascript back to auto-it through the clipboard memory.

This has no affect on the actual page source, only the in-memory copy. Simply reload the page.

Dale

Edit: Typo

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
soulhealer

i found it, it is window.clipboardData.setData("Text","text to put on clipboard")

the problem is, i dunno what to put on the clipboard. what is the var(on javascript) for the link that was gonna be halted/captured?

Edited by soulhealer

Share this post


Link to post
Share on other sites
DaleHohm

I don't understand what you are trying to accomplish.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
soulhealer

i found it

this.href

here's my idea:

#include <IE.au3>

$oIE = _IECreate("http://www.google.com")
$oLinks = _IELinkGetCollection($oIE)
For $oLink in $oLinks
    $sLinkId = $oLink.uniqueId
    _IEHeadInsertEventScript($oIE, $sLinkId, "onclick", "window.clipboardData.setData('Text',this.href);return false;")
Next

$oldclip = ""

While 1
    If $oldclip <> ClipGet() Then
       MsgBox(0,"hooray","the link clicked was " & ClipGet())
       $oldclip = ClipGet()
       Else
     ;
    EndIf
    Sleep(100)
WEnd

i just wanted the clicked link value can be retrieved by auto-it so i can put this on my main script, i believe this will work, so thanks a lot, i'm going to sleep now, gonna test this when i woke up. if u find any error or any better way, please post here again, i appreciate it, and again, thanks a lot :D

Edited by soulhealer

Share this post


Link to post
Share on other sites
Bert

It seems odd to want to do this. In all fairness, would you be willing to share what your intent to do with this code? Seems to me it could be used in a bad way. I would like to be wrong on this..... :D

Edited by Volly

Share this post


Link to post
Share on other sites
DaleHohm

Nice, but you can get the same result in the code I posted without using the clipboard or doing any polling if you add your MsgBox...

#include <IE.au3>

$oIE = _IECreate("http://www.google.com")
$oLinks = _IELinkGetCollection($oIE)
For $oLink in $oLinks
    $sLinkId = $oLink.uniqueId
    _IEHeadInsertEventScript($oIE, $sLinkId, "onclick", "return false;")
    ObjEvent($oLink, "_Evt_")
Next

While 1
    Sleep(100)
WEnd

Func _Evt_onclick()
    Local $o_link = @COM_EventObj
    ConsoleWrite($o_link.href & @CR)
    MsgBox(0,"hooray","the link clicked was " & $o_link.href)
EndFunc

Edit: typo

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
soulhealer

Nice, but you can get the same result in the code I posted without using the clipboard or doing any polling if you add your MsgBox...

#include <IE.au3>

$oIE = _IECreate("http://www.google.com")
$oLinks = _IELinkGetCollection($oIE)
For $oLink in $oLinks
    $sLinkId = $oLink.uniqueId
    _IEHeadInsertEventScript($oIE, $sLinkId, "onclick", "return false;")
    ObjEvent($oLink, "_Evt_")
Next

While 1
    Sleep(100)
WEnd

Func _Evt_onclick()
    Local $o_link = @COM_EventObj
    ConsoleWrite($o_link.href & @CR)
    MsgBox(0,"hooray","the link clicked was " & $o_link.href)
EndFunc

Edit: typo

yes, yours work perfectly :D i'm attaching yours now in my main script, thanks. Edited by soulhealer

Share this post


Link to post
Share on other sites
zackrspv

yes, yours work perfectly :blink: i'm attaching yours now in my main script, thanks.

What if you want to detect the links on a page that is always updating? Like in my situation, I have a live embeded IE window, that constantly has links being added to it. So, inserting the event handler when the IE window is created isn't going to work.

I need to be able to detect the link that was clicked, so that I can execute a function, code, or launch the browser. For example, if the link clicked is like: #STSTS-THIS%20ONE; then it would execute a function, or if it was a normal link that includes :// then it would execute the local browser to that address.

This basically allows me to respond to content in the embeded IE window, that is always changing, and fire off events, or normal actions.

Thanks!


-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.