Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

_IEHeadInsertEventScript speed issues


  • Please log in to reply
10 replies to this topic

#1 Juvigy

Juvigy

    Experimental Drugs Abuser

  • Active Members
  • PipPipPipPipPipPip
  • 1,280 posts

Posted 22 September 2010 - 08:09 AM

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, 22 September 2010 - 08:27 AM.








#2 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 22 September 2010 - 02:18 PM

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

#3 Juvigy

Juvigy

    Experimental Drugs Abuser

  • Active Members
  • PipPipPipPipPipPip
  • 1,280 posts

Posted 22 September 2010 - 02:51 PM

Not sure i quite get you. Can you post a small example of what you mean please ?

#4 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 22 September 2010 - 03:04 PM

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

#5 Juvigy

Juvigy

    Experimental Drugs Abuser

  • Active Members
  • PipPipPipPipPipPip
  • 1,280 posts

Posted 22 September 2010 - 03:15 PM

It seems my brain is off today . See my original post's edit part.
It does exactly what you suggest but how can i pass the javascript 'tname' variable to autoit so i can call _IEnavigate(link) for example?

#6 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 22 September 2010 - 05:25 PM

It would be:
$sVal = $oIE.document.parentwindow.eval("java script:tname")


;)
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

#7 Juvigy

Juvigy

    Experimental Drugs Abuser

  • Active Members
  • PipPipPipPipPipPip
  • 1,280 posts

Posted 23 September 2010 - 06:54 AM

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, 23 September 2010 - 09:26 AM.


#8 Juvigy

Juvigy

    Experimental Drugs Abuser

  • Active Members
  • PipPipPipPipPipPip
  • 1,280 posts

Posted 23 September 2010 - 02:57 PM

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) .

#9 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,974 posts

Posted 23 September 2010 - 04:30 PM

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


#10 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 23 September 2010 - 06:06 PM

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, 23 September 2010 - 06:07 PM.

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

#11 Juvigy

Juvigy

    Experimental Drugs Abuser

  • Active Members
  • PipPipPipPipPipPip
  • 1,280 posts

Posted 24 September 2010 - 06:41 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users