Solved

call javascript from visual basic

Posted on 2001-07-09
4
462 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

691 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