?
Solved

call javascript from visual basic

Posted on 2001-07-09
4
Medium Priority
?
475 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

850 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