Solved

Can a js script be forced to activate on a web page?

Posted on 2004-04-07
3
154 Views
Last Modified: 2010-05-02
Can VB force a javascript command on a web page? And if not, can a click event be forced on a gif if it doesn't have a name assigned to it?

I have a form on a web page that I need to populate and then submit. The gif has an onClick event that activates a javascript checkForm...the script then submits the form.

I either need to force a click event on the gif, or just activate the js script.

Thanks!
0
Comment
Question by:AmyL
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 500 total points
ID: 10780952
Private Sub Command1_Click()
    Dim iLoop As Integer
    For iLoop = 0 To WebBrowser1.Document.All.tags("IMG").length - 1
        If WebBrowser1.Document.All.tags("IMG")(iLoop).src = "file:///c:/test.bmp" Then
            WebBrowser1.Document.All.tags("IMG")(iLoop).Click
        End If
    Next iLoop
End Sub
Private Sub Form_Load()
    WebBrowser1.Navigate "c:\test.html"
End Sub


The above searches for an IMG and if it's src (location of image) is "file:///c:/test.bmp", it'll Click it. I had an OnClick javascript alert tagged to the image and it worked for me. It'd be more efficient if you could use IHTMLElementCollection but the above is fine also and you don't have to worry about an additional reference.
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10781031
>> or just activate the js script.

Lack of questions and had too much sugar so..

There's a execScript method that allows you to either pass the actual javascript "code" to execute or just the name of a pre-existing function. Since you probably know the function name..

Private Sub Command1_Click()
    WebBrowser1.document.parentWindow.execScript "MyScript()"
End Sub
Private Sub Form_Load()
    WebBrowser1.navigate "c:\test.html"
End Sub
0
 
LVL 76

Expert Comment

by:David Lee
ID: 10788985
AmyL,

Are you looking to do this with an external VB program (i.e. a standalone Exe)  or are you looking for some vbscript you can add to the web page that'll accomplish this task?
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now