我用VB做了个全屏的窗,现在用它来打开本地网页,代码如下:Private Sub Form_Load()
    Me.Width = Screen.Width
    Me.Height = Screen.Height
    WebBrowser1.Top = 0
    WebBrowser1.Left = 0
    WebBrowser1.Width = Screen.Width
    WebBrowser1.Height = Screen.Height
    WebBrowser1.Navigate "http://127.0.0.1"
End Sub系统默认打开的是index.htm文件
那么,这个窗体无标题栏,也无关闭按钮,现在我想在index.htm里用图片做一个关闭按钮,那么代码怎么写呢?在WebBrowser1里点击那个按钮就能关闭应用程序。

解决方案 »

  1.   

    借助BeforeNavigate2事件可以实现。
    首先在index.htm里,将关闭功能的图片做一个超链接,如:end。
    当点击此图片时,控件会触发BeforeNavigate2事件,并将这个链接值以URL参数传递到事件过程中,所以:Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)    If URL = "END" then
              ' 结束程序
              unload me
        End IfEnd Sub
      

  2.   

    网页里面这么写 
    <a href="end"><img src="关闭.gif"></a>
    程序如上面所说Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)    If URL = "END" then
             end
        End IfEnd Sub
    BeforeNavigate2 Event--------------------------------------------------------------------------------DescriptionOccurs when the WebBrowser control is about to navigate to a different URL, which may happen as a result of external automation, internal automation from a script, or the user clicking a link or typing in the address bar. The container has an opportunity to cancel the pending navigation. 
    Syntax
    Private Sub object_BeforeNavigate2(ByVal pDisp As Object, ByVal URL As String, 
    ByVal Flags As Long, ByVal TargetFrameName As String, PostData As Variant, 
    ByVal Headers As String, Cancel As Boolean)Value Description 
    object Required. An object expression that evaluates to an object in the Applies To list. 
    pDisp An object that evaluates to the top-level or frame WebBrowser object corresponding to the navigation.  
    URL A string expression that evaluates to the URL to which the browser is navigating.  
    Flags Reserved for future use.  
    TargetFrameName A string expression that evaluates to the name of the frame in which the resource will be displayed, or NULL if no named frame is targeted for the resource. 
    PostData Data to send to the server if the HTTP POST transaction is being used.  
    Headers A value that specifies the additional HTTP headers to send to the server (HTTP URLs only). The headers can specify things like the action required of the server, the type of data being passed to the server, or a status code. 
    Cancel A Boolean value that the container can set to TRUE to cancel the navigation operation, or to FALSE to allow it to proceed.  
      

  3.   

    Private Sub Form_Load()
        Me.Width = Screen.Width
        Me.Height = Screen.Height
        WebBrowser1.Top = 0
        WebBrowser1.Left = 0
        WebBrowser1.Width = Screen.Width
        WebBrowser1.Height = Screen.Height
        WebBrowser1.Navigate "http://127.0.0.1"
    End SubPrivate Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
        If URL = "END" Then
           If MsgBox("真的要退出程序吗?", vbYesNo, "退出程序") = vbYes Then
                 Unload Me
                 End
           End If
        End If
    End Sub------------ index.htm ---------
    <a href="END" onFocus="if(this.blur)this.blur()"><img src="images/login/login_09.jpg" width="90" height="96" border="0" alt="退出系统"></a>这样写了,还是不行,点退出还是一片空白
      

  4.   

    URL = "END" 执行不到这里来
      

  5.   

    看你安装的IE的版本了,如果是IE6的话Webbrowser控件有WindowClosing事件的,你只要在脚本里面调用window.close方法关闭网页就可以了。
      

  6.   

    关于windowclosing事件的说明参见:http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/events/windowclosing.asp
      

  7.   

    行了,原来要加上 url="http://127.0.0.1/END"