Solved

call javascript from visual basic

Posted on 2001-07-09
4
456 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB 6.0 printer how to align 6 58
Visual Basic Excel Formatting error 4 83
WPF issue with Trigger 2 96
Is IHttpActionResult a promise pattern? 2 57
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

896 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now