Sign in to follow this  
Followers 0
cascius

_IE and Javascript

5 posts in this topic

#1 ·  Posted (edited)

----------SOLVED----------

See my last post for solution. :(

--------------------------

Hi guys, I was reading through IE.au3 but didn't find a function to run a javascript. I did find _IEHeadInsertEventScript, but my understanding is that this will add JS code to the header, not run it.

In my case, I already have the javascript function DoSomething() in the header and just want to call it.

Can anyone help me? I feel I'm missing something obvious :s

Thanks,

- Cascius

Edited by cascius

Share this post


Link to post
Share on other sites



What are you trying to do? There may be an easier way...


Be nice to the newbies... we were all there once...[size="3"]Being right too soon is socially unacceptable. - R. Heinlein[/size]My Projects:OpenKiosk Browser

Share this post


Link to post
Share on other sites

Essentially I'm trying to automate some actions on one of my site.

Right now I have a script parsing through the HTML looking for an item with a certain innerText, and click it. That item has a javascript attached to it. I've been getting various results with this: sometimes the script thinks it has performed the click but nothing happens; some other times it works just fine...

The things is, rather than going through this complex parsing and then trying that click, I'd rather use the function attached to it directly. In the following example it would be: "DoSomething(2,22)"

Here's a simplified example:

Sample page content

<div id="navigation">
    <a onclick="DoSomething(1,22);return false;" class="button"><span>Do Something 1</span></a>
    <a onclick="DoSomething(2,22);return false;" class="button"><span>Do Something 2</span></a>
    <a onclick="DoSomething(3,22);return false;" class="button"><span>Do Something 3</span></a>
</div>

Sample Au3 script

$DoSomethingDiv = _IEGetObjByName($oIE, "navigation")                   ;Find "navigation", the container of those links:
$DoSomethingLinks = _IETagnameGetCollection($DoSomethingDiv, "a")       ;Create a collection of all the links within "navigation"
For $DoSomethingLink In $DoSomethingLinks                               ;Loop through the collection of links
    $DoSomethingLinkText = $DoSomethingLink.innerText                   ;Get the innerText of each link
    If StringInStr($DoSomethingLinkText, "Do Something 2") Then         ;check if the innerText matches the value "Do something 2"
        _IEAction($DoSomethingLink, "click")                            ;Click the link
        _IELoadWait($oIE, 0, 7000)                                      ;Wait for page to be loaded
        ExitLoop
    EndIf
Next

So what's really annoying is that "_IEAction($DoSomethingLink, "click")" doesn't always work in this case. I have it working flawlessly elsewhere, but this one is bugging me. Since I already know the JS function would be "DoSomething(2,22)", I'm thinking there might be a way to avoid all this hassle and just invoke it.

Does it make sense?

Thanks,

- Cascius

Share this post


Link to post
Share on other sites

Solved!

Here's what I used:

$oIE.document.parentwindow.execScript('DoSomething(1,22);')

I hope this will be useful to someone.

- Cascius

2 people like this

Share this post


Link to post
Share on other sites

+1 Very useful, the developer for our pages left out id's/names for many objects making somethings impossible without directly calling Jscript!

Thankyou

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