Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-07
3
Medium Priority
?
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

715 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