954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Javascript call VB function

Hi all..i make a program use javascript to call VB.Net function..but it doesn't work...can somebody help me to check this code...

Imports System.Runtime.InteropServices

<ComVisible(True)> _
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.ObjectForScripting = True
        WebBrowser1.DocumentText = "<Script language='JavaScript'>" & vbCrLf & _
                    "function callfunction() { " & vbCrLf & _
                    "window.external.cfunction();" & vbCrLf & _
                    "}" & vbCrLf & _
                    "</script>" & vbCrLf & _
                "<a href=# onclick='callfunction'>test</a>"
    End Sub

    Public Sub cfunction()
        MsgBox("test saja", MsgBoxStyle.ApplicationModal, ProductName)
        'Return 0
    End Sub
End Class
soeppp
Newbie Poster
9 posts since Aug 2009
Reputation Points: 8
Solved Threads: 0
 

Change:
Webbrowser1.ObjectForScripting = true

to:
Webbrowser1.ObjectForScripting = Me

Greetz,
Marc

wmdonkers
Newbie Poster
2 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

thanks buddy.. it works really better than other codes.

shazi786
Newbie Poster
1 post since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You