Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Simulating mouse click in AxWebBrowser window to a javascript link

Posted on 2005-04-19
7
Medium Priority
?
1,361 Views
Last Modified: 2008-01-09
I need to simulate a mouse click on a link in a web page using the AxWebBrowser control in my application.  The link that I am going to simulate the click on is pointed to "javascript:PageDown();"  Is there anyway to send the browser a command to do this or to simulate the clicking of the page down button?
0
Comment
Question by:kevandju
7 Comments
 
LVL 3

Expert Comment

by:angelfeijoo
ID: 13818879
Kevandju,

Yes. The way to click an item is:

AxWebBrowser1.Document.all.item( nItemIndex ).click()

But you would need to identify the nItemIndex first. The items expose many useful properties, like:

TAGNAME: Which for your case should be "A"
HREF: The link. As you know the destination link, you can just scan all items in Document.all until you find one item with TagName="A" and HRef = "javascript:PageDown();"

Angel


0
 

Author Comment

by:kevandju
ID: 13818976
Angel,

  I'm relatively new to VB .NET and I don't understand this part

"But you would need to identify the nItemIndex first. The items expose many useful properties, like:

TAGNAME: Which for your case should be "A"
HREF: The link. As you know the destination link, you can just scan all items in Document.all until you find one item with TagName="A" and HRef = "javascript:PageDown();" "

What do you mean by scan all items in Document.all?  What is the purpose of the TagName?
0
 
LVL 12

Assisted Solution

by:S-Twilley
S-Twilley earned 600 total points
ID: 13819043
Add a reference to your project... (within COM)  Microsoft HTML Library:

=========

Once added... try something like this... I rushed this, so let me know if it causes some probs... I'll have to create some sort of test page to see if it works :)

        Dim thisDoc As mshtml.IHTMLDocument2 = AxWebBrowser1.Document

        Dim thisElement As mshtml.IHTMLElement

        For Each thisElement In thisDoc.all.tags("A")
            Dim thisAnchor As mshtml.IHTMLAnchorElement = DirectCast(thisElement, mshtml.IHTMLAnchorElement)
            If thisElement.href.ToLower = "javascript:pagedown();" Then
                thisElement.click()
            End If
        Next
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Accepted Solution

by:
angelfeijoo earned 1400 total points
ID: 13819079
My code is similar:

        For Each objItem As Object In AxWebBrowser1.Document.All.Tags("A")
                If objItem.HRef = "javascript:PageDown();" Then
                    objItem.Click()
                    Exit For
                End If
        Next
0
 
LVL 32

Expert Comment

by:Erick37
ID: 13819148
You can also scroll the document regardless of what is loaded in the window:

'the amount of the vertical scroll
Dim sh As Integer = AxWebBrowser1.Height - 20
'scroll the window x,y
AxWebBrowser1.Document.parentWindow.scrollby(0, sh)
0
 

Author Comment

by:kevandju
ID: 13819196
Erick37 It is not actually a link to scroll down, but rather loads a whole new page with different content.  Angelfeijoo thanks again your code worked perfectly, thanks to S-Twilley too for your input.
0
 
LVL 3

Expert Comment

by:angelfeijoo
ID: 13819273
You're welcome.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question