Results 1 to 8 of 8

Thread: SET HTML and Iframe problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    91

    Question SET HTML and Iframe problem

    Hey Folks,

    I have the below code setup to display my own context menu for the WebBrowser1 control. However, I sorta ran into a snag since my main web page has an Iframe. The contextmenu works fine on the index page itself but if i right click in the iframe window it doesn't keep the contextmenu. I've provided the below code so you can see.

    Code:
    Option Explicit
    
    Public WithEvents HTML As HTMLDocument
    
    Private Function HTML_oncontextmenu() As Boolean
       HTML_oncontextmenu = False
       PopupMenu mnuContext '<---Check the mnu to your own menu name
    End Function
    
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        
        Set HTML = WebBrowser1.document
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
       Set HTML = Nothing
    End Sub
    Any help would be appreciated, thanks.
    n3m.

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: SET HTML and Iframe problem

    Give me an example of a URL that has an IFrame

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    91

    Question Re: SET HTML and Iframe problem

    Hey,

    I can't give a direct link unfortunately due to the site being a secure site and requires a login and there is confidential information. HOwever, the way the page is setup is as follows.

    When the user logs in, they are brought to webapp.php, the webapp.php has an iframe in that page with the following code:

    Code:
    <iframe src="iframes/check_user.php" id='cf1' name='cf1' width="100%" height="100%" frameborder="0" allowtransparency="true" hspace="0" vspace="0" align='left' valign='top' scrolling="no"></iframe>
    The vb application houses this site in it so people can't close out of it with an 'x' button and is forced to use our login/logout system.

    However, when they first login, they are brought to webapp.php, anywhere you click within webapp.php the context menu pops up fine, but once you right click over the iframe 'cf1' it shows the default IE context menu and not the custom one. It seems that the context menu isn't being applied to all document objects in the webbrowser1?

    n3m

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: SET HTML and Iframe problem

    I wasn't asking for your particular site. Do you not know of any URL that has IFrame?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    91

    Re: SET HTML and Iframe problem

    This site has an iframe:
    http://www.w3schools.com/TAGS/tag_iframe.asp

    When I navigate to this site with webbrowser1.navigate it also gives me the same issue, it seems like whenever there is an iframe the contextmenu is lost when hovering over it and hitting rightclick on mouse, is there something I should be capturing on the DocumentComplete to get the iframe contextmenu set?
    Last edited by n3mesis125; Oct 19th, 2008 at 10:59 PM.

  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: SET HTML and Iframe problem

    OK, thanks for the link. I understand now what you are up against. I'll see what I can work out.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    91

    Re: SET HTML and Iframe problem

    Thanks JM,

    Its a tough one, been googling for the past few hours to no avail Gonna be a late night for me and early morning *cry* hehe

  8. #8
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: SET HTML and Iframe problem

    OK, I think I have an answer for you. At least it worked for me.
    Code:
    Option Explicit
    
    Dim MyURL As String
    
    Public WithEvents HTML As HTMLDocument
    Public WithEvents HTML_I As HTMLDocument
    
    Private Function HTML_oncontextmenu() As Boolean
     '
     ' This one for the main page
     '
     HTML_oncontextmenu = False
     PopupMenu MyMenuEditor
    End Function
    
    Private Function HTML_I_oncontextmenu() As Boolean
     '
     ' This one for the IFrame page
     '
     HTML_I_oncontextmenu = False
     PopupMenu MyMenuEditor
    End Function
    
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
     If InStr(URL, MyURL) > 0 Then
       Set HTML = WebBrowser1.Document
       Set HTML_I = WebBrowser1.Document.frames(1).Document
     End If
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
     Set HTML = Nothing
     Set HTML_I - Nothing
    End Sub
    
    Private Sub Command1_Click()
     MyURL = "http://www.w3schools.com/TAGS/tag_iframe.asp"
     WebBrowser1.Navigate MyURL
    End Sub
    
    Private Sub Form_Load()
     MyURL = "NOTHING"
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width