BurningWheels
asked on
Refresh frame webbrowser
Hi Experts,
I would like to know how to refresh a childframe or iframe within a webpage. I don´t use the standard context menu. But the refresh option in the standard context menu is what i would like to be able to do. When i use webbrowser1.refresh it reloads the entire page not just the frame where the mouse is over.
Any suggestions?
Thanks.
I would like to know how to refresh a childframe or iframe within a webpage. I don´t use the standard context menu. But the refresh option in the standard context menu is what i would like to be able to do. When i use webbrowser1.refresh it reloads the entire page not just the frame where the mouse is over.
Any suggestions?
Thanks.
ASKER
I am displaying a frameset or a webpage with an iframe. I want to refresh the frame which the mouse is over. I am using the webbrowser control in Visual Basic .NET. The solution you provided has to do with the webpage itself as far as i understood it.
You can find a frame webbrowser in 2.0
liek
WebBrowser1.Document.Windo w.Frames(2 )
where 2 is the number of frame. you can iterate thourgh frames
for webbrowser in 1.1.
https://www.experts-exchange.com/questions/21166050/How-to-use-axWebBrowserto-get-the-HTML-source-of-the-page-in-a-frameset.html
liek
WebBrowser1.Document.Windo
where 2 is the number of frame. you can iterate thourgh frames
for webbrowser in 1.1.
https://www.experts-exchange.com/questions/21166050/How-to-use-axWebBrowserto-get-the-HTML-source-of-the-page-in-a-frameset.html
After finding the frame, you can use the navigate method to navigate it to self
ASKER
How can you which frame the mouse is over??
each frame is an Object of HtmlWindow,
in dotnet 2.0
attach GotFocus handler to it
Somthing like
Private Sub frame1_GotFocus(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlE lementEven tArgs) Handles x.GotFocus
End Sub
...in Dotnet 1.1
you can look for mshtml.HTMLWindow2Class and
and try events
Private Sub y_HTMLWindowEvents_Event_o nfocus() Handles y.HTMLWindowEvents_Event_o nfocus
End Sub
Private Sub y_HTMLWindowEvents2_Event_ onfocus(By Val pEvtObj As mshtml.IHTMLEventObj) Handles y.HTMLWindowEvents2_Event_ onfocus
End Sub
in dotnet 2.0
attach GotFocus handler to it
Somthing like
Private Sub frame1_GotFocus(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlE
End Sub
...in Dotnet 1.1
you can look for mshtml.HTMLWindow2Class and
and try events
Private Sub y_HTMLWindowEvents_Event_o
End Sub
Private Sub y_HTMLWindowEvents2_Event_
End Sub
If above things fails, which i think will not .. :)
Then
handle the click event of all Frame Documents , Something like
Private Sub document_Click(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlE lementEven tArgs) Handles document.Click
and you will know which doucment was clicked
Then
handle the click event of all Frame Documents , Something like
Private Sub document_Click(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlE
and you will know which doucment was clicked
Hi
Why have you given C. Wasnt the answer helpfull ?
Why have you given C. Wasnt the answer helpfull ?
ASKER
The answer was helpfull.
The problem with your code is that i don´t know how many frames and frames within those frames are being showed. I now have to iterate through all frames detect if the mouse is over by checking mouse position versus frame x and y and widht and height. Then check all frames within those frames etc... So it´s not a solution that works in every scenario.
What i really want to do is mimic the refresh function in the context menu of Internet Explorer.
Any other suggestions?
The problem with your code is that i don´t know how many frames and frames within those frames are being showed. I now have to iterate through all frames detect if the mouse is over by checking mouse position versus frame x and y and widht and height. Then check all frames within those frames etc... So it´s not a solution that works in every scenario.
What i really want to do is mimic the refresh function in the context menu of Internet Explorer.
Any other suggestions?
Actually in my opinion. 2nd last option which i gave will work for all scenarios.
cuz in main document complete.. you can just make a recursive function which can give you all the frames and you can add gotfocused event to all of them..
Then where ever is mouse clicked. you will get the corresponding Frame. and you will just do the navigate to self
cuz in main document complete.. you can just make a recursive function which can give you all the frames and you can add gotfocused event to all of them..
Then where ever is mouse clicked. you will get the corresponding Frame. and you will just do the navigate to self
ASKER
Could you explain that option a little further? When I copy your code i get a message:
Error 1 Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
I´m quite inexperienced when it comes to vb.net... ;)
This is the code i use now.... I don´t trust it entirely... in some cases it works sometimes not..
Dim tel As Integer, tel2 As Integer, tel3 As Integer, MouseX As Integer, MouseY As Integer
Dim FrameX1 As Integer, FrameX2 As Integer, FrameY1 As Integer, FrameY2 As Integer
MouseX = MousePosition.X.ToString
MouseY = MousePosition.Y.ToString
For tel = 0 To WebBrowser1.Document.Windo w.Frames.C ount - 1
FrameX1 = WebBrowser1.Document.Windo w.Frames(t el).Positi on.X
FrameX2 = WebBrowser1.Document.Windo w.Frames(t el).Size.W idth + FrameX1
FrameY1 = WebBrowser1.Document.Windo w.Frames(t el).Positi on.Y
FrameY2 = WebBrowser1.Document.Windo w.Frames(t el).Size.H eight + FrameY1
If MouseX > FrameX1 And MouseX < FrameX2 Then
If MouseY > FrameY1 And MouseY < FrameY2 Then
If WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames.Cou nt = 0 Then
Dim readme As Object = Nothing
WebBrowser1.Document.Windo w.Frames(t el).Docume nt.ExecCom mand("refr esh", True, readme)
Exit Sub
Else
For tel2 = 0 To WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames.Cou nt - 1
FrameX1 = WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames(tel 2).Positio n.X
FrameX2 = WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames(tel 2).Size.Wi dth + FrameX1
FrameY1 = WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames(tel 2).Positio n.Y
FrameY2 = WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames(tel 2).Size.He ight + FrameY1
If MouseX > FrameX1 And MouseX < FrameX2 Then
If MouseY > FrameY1 And MouseY < FrameY2 Then
If WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames(tel 2).Documen t.Window.F rames.Coun t = 0 Then
Dim readme As Object = Nothing
WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames(tel 2).Documen t.ExecComm and("refre sh", True, readme)
Exit Sub
Else
For tel3 = 0 To WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames(tel 2).Documen t.Window.F rames.Coun t - 1
FrameX1 = WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames(tel 2).Documen t.Window.F rames(tel3 ).Position .X
FrameX2 = WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames(tel 2).Documen t.Window.F rames(tel3 ).Size.Wid th + FrameX1
FrameY1 = WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames(tel 2).Documen t.Window.F rames(tel3 ).Position .Y
FrameY2 = WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames(tel 2).Documen t.Window.F rames(tel3 ).Size.Hei ght + FrameY1
If MouseX > FrameX1 And MouseX < FrameX2 Then
If MouseY > FrameY1 And MouseY < FrameY2 Then
If WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames(tel 2).Documen t.Window.F rames(tel3 ).Document .Window.Fr ames.Count = 0 Then
Dim readme As Object = Nothing
WebBrowser1.Document.Windo w.Frames(t el).Docume nt.Window. Frames(tel 2).Documen t.Window.F rames(tel3 ).Document .ExecComma nd("refres h", True, readme)
Exit Sub
Else
End If
End If
End If
Next tel3
End If
End If
End If
Next tel2
End If
End If
End If
Next tel
Error 1 Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
I´m quite inexperienced when it comes to vb.net... ;)
This is the code i use now.... I don´t trust it entirely... in some cases it works sometimes not..
Dim tel As Integer, tel2 As Integer, tel3 As Integer, MouseX As Integer, MouseY As Integer
Dim FrameX1 As Integer, FrameX2 As Integer, FrameY1 As Integer, FrameY2 As Integer
MouseX = MousePosition.X.ToString
MouseY = MousePosition.Y.ToString
For tel = 0 To WebBrowser1.Document.Windo
FrameX1 = WebBrowser1.Document.Windo
FrameX2 = WebBrowser1.Document.Windo
FrameY1 = WebBrowser1.Document.Windo
FrameY2 = WebBrowser1.Document.Windo
If MouseX > FrameX1 And MouseX < FrameX2 Then
If MouseY > FrameY1 And MouseY < FrameY2 Then
If WebBrowser1.Document.Windo
Dim readme As Object = Nothing
WebBrowser1.Document.Windo
Exit Sub
Else
For tel2 = 0 To WebBrowser1.Document.Windo
FrameX1 = WebBrowser1.Document.Windo
FrameX2 = WebBrowser1.Document.Windo
FrameY1 = WebBrowser1.Document.Windo
FrameY2 = WebBrowser1.Document.Windo
If MouseX > FrameX1 And MouseX < FrameX2 Then
If MouseY > FrameY1 And MouseY < FrameY2 Then
If WebBrowser1.Document.Windo
Dim readme As Object = Nothing
WebBrowser1.Document.Windo
Exit Sub
Else
For tel3 = 0 To WebBrowser1.Document.Windo
FrameX1 = WebBrowser1.Document.Windo
FrameX2 = WebBrowser1.Document.Windo
FrameY1 = WebBrowser1.Document.Windo
FrameY2 = WebBrowser1.Document.Windo
If MouseX > FrameX1 And MouseX < FrameX2 Then
If MouseY > FrameY1 And MouseY < FrameY2 Then
If WebBrowser1.Document.Windo
Dim readme As Object = Nothing
WebBrowser1.Document.Windo
Exit Sub
Else
End If
End If
End If
Next tel3
End If
End If
End If
Next tel2
End If
End If
End If
Next tel
Ok :)
let me give you the VB code
Private Sub WebBrowser1_DocumentComple ted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBr owserDocum entComplet edEventArg s) Handles WebBrowser1.DocumentComple ted
AddHandlerToFrames(WebBrow ser1.Docum ent.Window .Frames)
End Sub
Private Sub AddHandlerToFrames(ByVal h As HtmlWindowCollection)
For Each window As HtmlWindow In h
RemoveHandler window.GotFocus, AddressOf s1_GotFocus
AddHandler window.GotFocus, AddressOf s1_GotFocus
If window.Frames IsNot Nothing AndAlso window.Frames.Count > 0 Then
AddHandlerToFrames(window. Frames)
End If
Next
End Sub
Private Sub s1_GotFocus(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlE lementEven tArgs)
CType(sender, HtmlWindow).Document.ExecC ommand("re fresh", False, Nothing)
End Sub
let me give you the VB code
Private Sub WebBrowser1_DocumentComple
AddHandlerToFrames(WebBrow
End Sub
Private Sub AddHandlerToFrames(ByVal h As HtmlWindowCollection)
For Each window As HtmlWindow In h
RemoveHandler window.GotFocus, AddressOf s1_GotFocus
AddHandler window.GotFocus, AddressOf s1_GotFocus
If window.Frames IsNot Nothing AndAlso window.Frames.Count > 0 Then
AddHandlerToFrames(window.
End If
Next
End Sub
Private Sub s1_GotFocus(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlE
CType(sender, HtmlWindow).Document.ExecC
End Sub
ASKER
Thanks for the code. It doesn´t seem to work as i expected. Now, everytime a frame receives focus it refreshes. Is there a way to make it refresh when a user clicks a menu item??
Something like:
ToolStripMenuItem_Click(By Val sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem.Click
CType(sender, HtmlWindow).Document.ExecC ommand("re fresh", False, Nothing)
End Sub
If it is going to work. I will give you more credit. if i can figure out how to reconsider my score for your answers.
Something like:
ToolStripMenuItem_Click(By
CType(sender, HtmlWindow).Document.ExecC
End Sub
If it is going to work. I will give you more credit. if i can figure out how to reconsider my score for your answers.
Oh sorry Send GotFocused Event.
It should be click event. Something like
Private Sub WebBrowser1_DocumentComple ted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBr owserDocum entComplet edEventArg s) Handles WebBrowser1.DocumentComple ted
AddHandlerToFrames(WebBrow ser1.Docum ent.Window .Frames)
End Sub
Private Sub AddHandlerToFrames(ByVal h As HtmlWindowCollection)
For Each window As HtmlWindow In h
RemoveHandler window.Document.Click, AddressOf s_Click
AddHandler window.Document.Click, AddressOf s_Click
If window.Frames IsNot Nothing AndAlso window.Frames.Count > 0 Then
AddHandlerToFrames(window. Frames)
End If
Next
End Sub
Private Sub s_Click(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlE lementEven tArgs)
CType(sender, HtmlDocument).ExecCommand( "refresh", False, Nothing)
End Sub
To reconsider the score.
Post a question in Community
https://www.experts-exchange.com/Community_Support/
to reopen Question
https://www.experts-exchange.com/questions/21956182/Refresh-frame-webbrowser.html
for changing of grades
It should be click event. Something like
Private Sub WebBrowser1_DocumentComple
AddHandlerToFrames(WebBrow
End Sub
Private Sub AddHandlerToFrames(ByVal h As HtmlWindowCollection)
For Each window As HtmlWindow In h
RemoveHandler window.Document.Click, AddressOf s_Click
AddHandler window.Document.Click, AddressOf s_Click
If window.Frames IsNot Nothing AndAlso window.Frames.Count > 0 Then
AddHandlerToFrames(window.
End If
Next
End Sub
Private Sub s_Click(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlE
CType(sender, HtmlDocument).ExecCommand(
End Sub
To reconsider the score.
Post a question in Community
https://www.experts-exchange.com/Community_Support/
to reopen Question
https://www.experts-exchange.com/questions/21956182/Refresh-frame-webbrowser.html
for changing of grades
ASKER
Now everytime i click on a page it refreshes. How do i trigger this only when i click an item in a custom menu?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I posted a message in Community to change the grades
You´re receiving 200 points and a grade A
You´re receiving 200 points and a grade A
<!--From a regular popup window:-->
if (opener && !opener.closed) opener.location.reload(1);
<!--If the popup window itself is a frameset:-->
top.opener.location.reload
<!--To close the popup and refresh the parent:-->
opener.location.reload(1);