Invoke Function or Sub from html button input


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Invoke Function or Sub from html button input

  1. #1
    Join Date
    Jan 2007
    Location
    Norway
    Posts
    6

    Thumbs down Invoke Function or Sub from html button input

    Hey

    I rely need help on this one.

    In my program i have an Webbrowser1 component witch i use to present different information to user.
    What I need if for this program to invoke an Function or Sub if user presses an input button in the webbrowser1 and identify what button that was pressed.

    Based on what button that was pressed, different action(Function or Sub) will start.

    Can anybody help me on this?

    Some useful info:
    I use MS Visual Studio 2010 and write the code in Visual Basic.

    Best regards,
    VillVest

  2. #2
    Join Date
    Jan 2007
    Location
    Norway
    Posts
    6
    I found a solution:
    Code:
    Imports System
    Imports System.Windows.Forms
    Imports System.Security.Permissions
    
    <PermissionSet(SecurityAction.Demand, Name:="FullTrust")> <System.Runtime.InteropServices.ComVisibleAttribute(True)> Public Class Form1
        Inherits Form
    
        Private webBrowser1 As New WebBrowser()
        Private WithEvents button1 As New Button()
    
        <STAThread()> _
        Public Shared Sub Main()
            Application.EnableVisualStyles()
            Application.Run(New Form1())
        End Sub
    
        Public Sub New()
            button1.Text = "call script code from client code"
            button1.Dock = DockStyle.Top
            webBrowser1.Dock = DockStyle.Fill
            Controls.Add(webBrowser1)
            Controls.Add(button1)
        End Sub
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    
            webBrowser1.AllowWebBrowserDrop = False
            webBrowser1.IsWebBrowserContextMenuEnabled = False
            webBrowser1.WebBrowserShortcutsEnabled = False
            webBrowser1.ObjectForScripting = Me
            ' Uncomment the following line when you are finished debugging.
            'webBrowser1.ScriptErrorsSuppressed = True
    
            webBrowser1.DocumentText = _
                "<html><head><script>" & _
                "function test(message) { alert(message); }" & _
                "</script></head><body><button " & _
                "onclick=""window.external.Test('called from script code')"" > " & _
                "call client code from script code</button>" & _
                "</body></html>"
    
        End Sub
    
        Public Sub Test(ByVal message As String)
            MessageBox.Show(message, "client code")
        End Sub
    
        Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
    
            webBrowser1.Document.InvokeScript("test", New String() {"called from client code"})
    
        End Sub
    
    End Class
    Last edited by Hack; 05-22-2012 at 12:04 PM.

Similar Threads

  1. Pseudocode Problem
    By zobi316 in forum VB Classic
    Replies: 3
    Last Post: 03-10-2008, 07:05 AM
  2. call function for button
    By angela_quests in forum VB Classic
    Replies: 2
    Last Post: 04-13-2007, 04:57 AM
  3. Replies: 2
    Last Post: 04-18-2005, 12:01 PM
  4. Button and input properties
    By glen in forum Web
    Replies: 1
    Last Post: 02-22-2001, 10:50 AM
  5. How do I detect an FTP timeout?
    By Julian Milano in forum VB Classic
    Replies: 2
    Last Post: 08-11-2000, 12:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center