Solved

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 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…
Suggested Courses
Course of the Month6 days, 19 hours left to enroll

623 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