Sign in to follow this  
Followers 0

_IEHeadInsertEventScript speed issues

11 posts in this topic

Posted (edited)

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

Share this post


Link to post
Share on other sites



Posted

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?

;)

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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.

;)

Share this post


Link to post
Share on other sites

Posted

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?

Share this post


Link to post
Share on other sites

Posted

It would be:

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

;)

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

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.

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  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.