Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA open file from excel cell 4 44
Validating VB6 Function 19 65
Help me. 3 60
VBA- How to change font, color and format in outlook e-mail sent from Access 2 70
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

830 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