Solved

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

Posted on 2004-04-07
3
156 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

Gigs: Get Your Project Delivered by an Expert

Select from 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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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