Jump to content

_IEHeadInsertEventScript speed issues


Juvigy
 Share

Recommended Posts

Now i have speed issues :

begin = TimerInit()
$oLinks = _IELinkGetCollection($object)
ConsoleWrite("Number of links"&@extended&@CRLF)
For $oLink in $oLinks
    $sLinkId = _IEPropertyGet($oLink, "uniqueid")
    _IEHeadInsertEventScript($object, $sLinkId, "onclick", "return false;")
    ObjEvent($oLink, "_Evt_")
Next
$dif = TimerDiff($begin)
ConsoleWrite("Time Difference"&$dif/1000&@CRLF)
EndFunc

For 700 links it takes 8 seconds. Any idea how i can speed this up?

@Edit i also tried :

$script = 'function whichElement(e){var tname;tname=e.srcElement.attributes("href").value;alert(tname);};whichElement(event);'
_IEHeadInsertEventScript ($oIE, "document", "onmousedown", $script)

But dont know how to return the link value back to the AutoIT for use.

Edited by Juvigy
Link to comment
Share on other sites

Since you're doing that to every link without discretion, can't you just put one event on the whole document and check the element type so as to only react to links?

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Look at Example #1 in the help file under _IEHeadInsertEventScript(). It's a single event for any 'onclick' in the 'document'. Use the javascript to take action only if the element clicked was a link.

That would only have to be set once, vice on each and every link element.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

For some reason it doesnt work - requested action with this object failed error.

@Edit. Here is my code:

$oDoc=_IETagNameGetCollection ($oIE, "body",0)
ObjEvent($oDoc,"_Evt_")
$script = 'function whichElement(e){var tname;tname=e.srcElement.attributes("href").value;};whichElement(event);'
_IEHeadInsertEventScript ($oIE,"document","onmousedown", $script)
While 1
    Sleep(10)
WEnd

Func _Evt_onclick()
    $asd=$oIE.document.parentwindow.eval("java script:tname")
    ConsoleWrite("Some test:"&$asd&@CRLF)
EndFunc

@Edit2

Removing all code and just attaching to the page and after that executing:

$asd=$oIE.document.parentwindow.eval("java script:show_advanced_bool")
ConsoleWrite("Some test:"&$asd&@CRLF)

Fails too.Any idea why? show_advanced_bool is existing in the webpage...

Edited by Juvigy
Link to comment
Share on other sites

Finally made some progress. It is a little bit dirty as i am overwriting a global variable-show_advanced_bool:

$script = 'function whichElement(e){var tname=0;show_advanced_bool=e.srcElement.attributes("href").value;return tname;};whichElement(event);'

_IEHeadInsertEventScript ($oIE,"document","onclick", "return false;") ; - prevent navigation

_IEHeadInsertEventScript ($oIE,"document","onmousedown", $script) ; - execute the script - couldnt figure how to extract tname - so i did overwrite show_advanced_bool

$oDoc=_IETagNameGetCollection ($oIE, "body",0)

ObjEvent($oDoc,"_Evt_")

While 1

Sleep(10)

WEnd

Func _Evt_onclick()

$asd=$oIE.document.parentwindow.eval('show_advanced_bool')

ConsoleWrite($asd&@CRLF)

EndFunc

Couldnt figure out how to get the return value form the function. and $oIE.document.parentwindow.eval('tname') didnt work. If someone can suggest better/cleaner way i am open for suggestions (Waiting for Dale) .

Link to comment
Share on other sites

If show_advanced_bool returns a value, it should be available to you in $asd (this is the difference between eval and execscript, whilch will not give you access to a return value). (See this thread for working examples: http://www.autoitscript.com/forum/index.php?showtopic=60098&st=0&p=452387&hl=execscript%20eval&fromsearch=1&)

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

Link to comment
Share on other sites

Is there something like a 'scope' issue here? The tname variable is 'local' to the event script that runs at onclick time.

Maybe it needs to be copied to a 'global' for AutoIt to be able to read it with .eval() at some other time.

Just asking, I don't know if that really makes sense in the context of Javascript inside an IE DOM.

;)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Is there something like a 'scope' issue here? The tname variable is 'local' to the event script that runs at onclick time.

Maybe it needs to be copied to a 'global' for AutoIt to be able to read it with .eval() at some other time.

Just asking, I don't know if that really makes sense in the context of Javascript inside an IE DOM.

;)

Exactly. As i cant get tname from the local script i just copied its value to show_advanced_bool which is a global variable of the page.

I think i will create a new global variable just to be safe as show_advanced_bool may be used and it is not good to overwrite its value.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...