Solved

call javascript from visual basic

Posted on 2001-07-09
4
461 Views
Last Modified: 2013-11-25
I have a DHTML page in a webbrowser control on a form...
how can I call javascript functions in my DHTML script from VB?

or if I cant how can I raise a DOM event instead, so I can trigger some script code...

Thanks!
0
Comment
Question by:LuckyPhill
  • 2
4 Comments
 
LVL 7

Expert Comment

by:Inteqam
ID: 6264285
Basically, you can't. You can't mix client-side javascript with server-side
vb script.
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 6264290
maybe

<% if foo then
Response.Write "<Script language='JavaScript'>alert('hello')</Script>"
end if
%>
0
 
LVL 6

Accepted Solution

by:
andyclap earned 50 total points
ID: 6267407
Inetgam - I think you have the wrong end of the stick here -
LuckyPhill wants to call a script in the page showing on the client in a webbrowser control from the VB host of the webbrowser,
e.g.
msgbox Form1.WebBrowser1.document.myFunc()

Naturally the above doesn't work, otherwise this question wouldn't be here ;)


What you can do is use the execScript command (which unfortunately won't give you a value back) in conjunction with a hidden element if you need to return a value.

eg - for a HTML page:
<html>
<body>
<input type="hidden" id="txtOut">
<script language="javascript">
function myFunc()
{
  return 'Wombat';
}
</script>
</body>
</html>

you can use in VB:
webbrowser1.document.parentWindow.execScript "txtOut.value=myFunc();","javascript"
msgbox Webbrowser1.document.all("txtOut").value
0
 
LVL 1

Author Comment

by:LuckyPhill
ID: 6267671
Thanks andyclap thats purrfect....!
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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…

696 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