GetRef and a Handler with parameters? 
Author Message
 GetRef and a Handler with parameters?

Hi, first of all: My english is so bad.I'm doing my best...

This is the problem. I want to handling all the "onclick" events of
the document.links() collection so I tried this:
        Set oIE = WScript.CreateObject("InternetExplorer.Application","oIE_")
        oIE.Navigate(" http://www.*-*-*.com/ ")
        oIE.Visible = True

        Do While True
                'Duerme 10 minutos y haz el bucle de nuevo.
                WScript.Sleep 36000000
        Loop

        Sub oIE_DocumentComplete(Byval pDisp, URL)
            WScript.Echo URL
            i = 0    
            Do While i <= (oIE.document.links.length - 1)
                      Set oIE.document.links(i).onclick = GetRef("Enlaces "+i)
              i = i + 1
            Loop
        End sub

        Sub Enlaces(Index)
                WScript.Echo Index
        End Sub

And i get the error that types doesn't been correct (translated from
spanish :D)

What it means? GetRef and handlers with arguments doesn't work?

How can i get the link that has been click on?

Thanks a lot and i hope that you're crying with my english lessons ;).



Mon, 05 Jul 2004 02:54:54 GMT  
 GetRef and a Handler with parameters?
1) you can't assign handlers with arguments to the onclick property.
2) GetRef wants only the name of a procedure without arguments.

Just hook all the onclick events to the same local handler

    Do While i <= (oIE.document.links.length - 1)
            Set oIE.document.links(i).onclick = GetRef("Enlaces")
      i = i + 1
    Loop

And change the handler to

Sub Enlaces() '<=== no argument
    WScript.Echo window.event.srcElement.<someproperty>
End Sub

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> Hi, first of all: My english is so bad.I'm doing my best...

> This is the problem. I want to handling all the "onclick" events of
> the document.links() collection so I tried this:
>    Set oIE = WScript.CreateObject("InternetExplorer.Application","oIE_")
> oIE.Navigate("http://www.google.com")
> oIE.Visible = True

> Do While True
> 'Duerme 10 minutos y haz el bucle de nuevo.
> WScript.Sleep 36000000
> Loop

> Sub oIE_DocumentComplete(Byval pDisp, URL)
>     WScript.Echo URL
>     i = 0    
>     Do While i <= (oIE.document.links.length - 1)
>             Set oIE.document.links(i).onclick = GetRef("Enlaces "+i)
>       i = i + 1
>     Loop
>         End sub

> Sub Enlaces(Index)
> WScript.Echo Index
> End Sub

> And i get the error that types doesn't been correct (translated from
> spanish :D)

> What it means? GetRef and handlers with arguments doesn't work?

> How can i get the link that has been click on?

> Thanks a lot and i hope that you're crying with my english lessons ;).



Mon, 05 Jul 2004 03:28:14 GMT  
 GetRef and a Handler with parameters?
Ahhh, this solution doesn't work! . I've tried with this but remember
i'm using and InternetExplorer object...?where is the window object?....

The error is:
   window object doesn't exists.

I've also tried :
   oIE.event.srcelement.<property>

and :
   oIE.window.event.srcelement.<property>

getting the same error....

Some idea?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Mon, 05 Jul 2004 03:57:18 GMT  
 GetRef and a Handler with parameters?
Sub Enlaces()
  WScript.Echo me.document.parentWindow.event.srcElement.href
  'or in this case just...
  'WScript.Echo me.href
End Sub

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> Ahhh, this solution doesn't work! . I've tried with this but remember
> i'm using and InternetExplorer object...?where is the window object?....

> The error is:
>    window object doesn't exists.

> I've also tried :
>    oIE.event.srcelement.<property>

> and :
>    oIE.window.event.srcelement.<property>

> getting the same error....

> Some idea?

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Mon, 05 Jul 2004 04:15:06 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Is it possible to use GetRef with parameters?

2. parameter of event handler of string

3. Add an event handler to the actual event handler for an element

4. GetRef question

5. GetRef and/or onreadystatechange problems

6. GetRef() help

7. GetRef with embedded VB COM objects

8. Question about GetRef-not in web page!

9. GETREF and VBScript Classes

10. GetRef in VBScript classes

11. GetRef function

12. Problem with GetRef in classes

 

 
Powered by phpBB® Forum Software