473,587 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript & WebBrowser1 control

Hi,

How can get the javascript using a button Command1 ?
I want to create the html on the fly.
This one doesn't work:

Private Sub Command1_Click( )
WebBrowser1.Nav igate "javascript:cal lAlert()"
End Sub

Private Sub WebBrowser1_Doc umentComplete(B yVal pDisp As Object, URL As Variant)

Dim sHTML As String
sHTML = "<P>This is some text.</P>"

sHTML = sHTML & "<script type=""text/javascript"">" & vbCrLf
sHTML = sHTML & "<!--" & vbCrLf
sHTML = sHTML & "function callAlert(){" & vbCrLf
sHTML = sHTML & "alert(""Test"" );" & vbCrLf
sHTML = sHTML & "}" & vbCrLf
sHTML = sHTML & " //-->" & vbCrLf
sHTML = sHTML & "</script>" & vbCrLf

WebBrowser1.Doc ument.body.inne rHTML = sHTML

End Sub
Jul 17 '05 #1
2 7764
put an html button on the page with an onClick event handler that calls the
javascript function
server-side script can't call client-side script functions

"Florin" <fl*****@mccowa n.ca> wrote in message
news:29******** *************** ***@posting.goo gle.com...
Hi,

How can get the javascript using a button Command1 ?
I want to create the html on the fly.
This one doesn't work:

Private Sub Command1_Click( )
WebBrowser1.Nav igate "javascript:cal lAlert()"
End Sub

Private Sub WebBrowser1_Doc umentComplete(B yVal pDisp As Object, URL As Variant)
Dim sHTML As String
sHTML = "<P>This is some text.</P>"

sHTML = sHTML & "<script type=""text/javascript"">" & vbCrLf
sHTML = sHTML & "<!--" & vbCrLf
sHTML = sHTML & "function callAlert(){" & vbCrLf
sHTML = sHTML & "alert(""Test"" );" & vbCrLf
sHTML = sHTML & "}" & vbCrLf
sHTML = sHTML & " //-->" & vbCrLf
sHTML = sHTML & "</script>" & vbCrLf

WebBrowser1.Doc ument.body.inne rHTML = sHTML

End Sub

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004
Jul 17 '05 #2

I didn't test your dynamic writing of the script tag,
but I'll assume that part works.
If you reference MSHTML.TLB in the project you
get access to the DOM.
I'm not sure what syntax you'll need to get access
to the script. Maybe something like this will work:

Dim Doc As mshtml.HTMLDocu ment
Set Doc = WebBrowser1.Doc ument
s = Doc.scripts.Ite m("callAlert()" )
Doc.parentWindo w. execScript("cal lAlert()", "javascript ")

--
--
Florin <fl*****@mccowa n.ca> wrote in message
news:29******** *************** ***@posting.goo gle.com...
Hi,

How can get the javascript using a button Command1 ?
I want to create the html on the fly.
This one doesn't work:

Private Sub Command1_Click( )
WebBrowser1.Nav igate "javascript:cal lAlert()"
End Sub

Private Sub WebBrowser1_Doc umentComplete(B yVal pDisp As Object, URL As Variant)
Dim sHTML As String
sHTML = "<P>This is some text.</P>"

sHTML = sHTML & "<script type=""text/javascript"">" & vbCrLf
sHTML = sHTML & "<!--" & vbCrLf
sHTML = sHTML & "function callAlert(){" & vbCrLf
sHTML = sHTML & "alert(""Test"" );" & vbCrLf
sHTML = sHTML & "}" & vbCrLf
sHTML = sHTML & " file://-->" & vbCrLf
sHTML = sHTML & "</script>" & vbCrLf

WebBrowser1.Doc ument.body.inne rHTML = sHTML

End Sub

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
24166
by: Trevor Fairchild | last post by:
I'm writing a program that is designed for quick navigation using specific buttons on the keyboard. In doing this, I have added a KeyPress event for every control on the form to intercept the key pressed and pass it to a standard subroutine that identifies what action should be taken. Unfortunately, I have a web-browser contol on the form...
0
3395
by: Juan Jose Costello Levien | last post by:
Hello, My name is Juan. I am new to the forum. Here I leave you a problem to see if you can help me. General Description I am developing an application in Visual Basic 6.
2
6118
by: FatBo | last post by:
Dear all, I am writing a Javascript which print a page without prompting the print dialog when the page is loaded. However, there is a warning box prompted out because I am requesting the privilege of client's computer. But my boss doesn't want to lower the security settings and doesn't want to see the prompt dialog. I am wonder that...
8
2794
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);" TextBox2.Attributes.Add("onKeyPress", jscode) You will notice that jscode contains the JavaScript Logical And operator (&&). However, ASP.NET renders this as...
16
9916
by: nime | last post by:
How can I grab html source of a frame? I can retrive main frame by WebBrowser1.DocumentText but I want to retrive inner (child) frame... WebBrowser1.Document.Window.Frames(0).DocumentText like thing doesn't exist...
11
2772
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or < or several others, it converts them to html, such as &amp; or &lt; which can sometimes cause my scripts not to work. How can I prevent ASP.NET from...
1
2797
by: chance | last post by:
My c# code: string path = Path.Combine(Path.GetDirectoryName(this.GetType().Assembly.Location), "VirtualEarth.htm"); webBrowser1.Navigate(path); webBrowser1.Document.InvokeScript("doSomething"); Javascript code:
0
1570
by: arindams | last post by:
I've a form where an webrowser contains a html file. I want to copy a selective portion of the html content and paste that content in an excel 2007 file where it will be pasted as a normal text (not in HTML code). I want to have the excel part should be as it is done manually (i.e. it should be in proper format as it is in the HTML file). ...
5
15986
by: maminx | last post by:
hello all, i want to call window print preview (in browser, File - Print Preview) by javascript, this is the code function printpreview() { var OLECMDID = 7; /* OLECMDID values: * 6 - print * 7 - print preview * 1 - open window
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.