Solved

call javascript from visual basic

Posted on 2001-07-09
4
454 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
Comment Utility
Basically, you can't. You can't mix client-side javascript with server-side
vb script.
0
 
LVL 7

Expert Comment

by:Inteqam
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks andyclap thats purrfect....!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
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 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…

771 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

15 Experts available now in Live!

Get 1:1 Help Now