Welcome Guest Search | Active Topics | Sign In | Register

New window popup Options
yleung
Posted: Thursday, April 24, 2014 9:45:51 PM
Rank: Advanced Member
Groups: Member

Joined: 4/2/2014
Posts: 37
Hi,

On a web page, there is a button. when you click it, it will call window.open javascript to open a new window. Everything works on browsers.

However, I try to load this page on EO.WebBrowser.WinForm.WebControl. When I click this button. everything hangs. I think I should do something on the NewWindow event. But what exactly should I do?

Thanks for the help!

Howie
eo_support
Posted: Thursday, April 24, 2014 11:11:35 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Hi,

You need to handle NewWindow event. See here for more details:

http://www.essentialobjects.com/doc/6/advanced/new_window.aspx

The key is when you call window.open the browser engine only creates a new WebView object. You are responsible to create the actual window (a Form in a Windows form application) and then place the newly created WebView inside that Form.

Thanks!
yleung
Posted: Tuesday, June 17, 2014 3:00:28 PM
Rank: Advanced Member
Groups: Member

Joined: 4/2/2014
Posts: 37
Thanks for the information.




I handle javascript popup by opening a new window rather than opening a new tab. Here is the code:

Private Sub AxWebBrowser2_NewWindow(ByVal sender As Object, ByVal e As EO.WebBrowser.NewWindowEventArgs)

e.Accepted = True

_WebBrowerOnPopup = New EO.WebBrowser.WinForm.WebControl
' create a popup

Dim popupForm As New System.Windows.Forms.Form
popupForm.ClientSize = New System.Drawing.Size(Convert.ToInt32(e.Width), Convert.ToInt32(e.Height))
popupForm.Controls.Add(_WebBrowerOnPopup)
_WebBrowerOnPopup.Dock = DockStyle.Fill
_WebBrowerOnPopup.WebView = e.WebView

popupForm.Show()
End Sub


This piece of code has performance issue.

The web browser loads a page that has a button called "Import data". I click this button to open a new window. Then I close the new window. Now if I wait for 10 seconds before I click the button again, a new window is popup without any problem. But If I don't wait for 10 seconds first before clicking again, the browser hangs for a few seconds. This doesn't happen on any browser including Google Chrome. Do you know why?

Here is the URL I am testing:
http://www.ironspeed.org/Howie1

After loading the page, click the "Actions" button. Then you will see the "Import data button".

Thanks again..


eo_support
Posted: Wednesday, June 18, 2014 9:49:01 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Hi,

We are not aware of anything that can cause such difference between 10 seconds before or after. Can you isolate the problem into a test project and send us the test project? We will look into it as soon as we have that.

Thanks!
yleung
Posted: Thursday, June 19, 2014 5:47:18 PM
Rank: Advanced Member
Groups: Member

Joined: 4/2/2014
Posts: 37
Thanks,

I just updated sent you an email with a sample code. Hope you can identify the problem.

Thanks
Yuenho
eo_support
Posted: Sunday, June 22, 2014 11:05:01 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Hi,

We have looked into your sample code. Please add the following code in your NewWindow handler:

Code: Visual Basic.NET
'Handle FormClosed event for the popup form
AddHandler popupForm.FormClosed, AddressOf Form_Closed


Form_Closed is a function that contains the following code:

Code: Visual Basic.NET
Private Sub Form_Closed(ByVal sender As Object, ByVal e As EventArgs)
    Dim popupForm As System.Windows.Forms.Form = _
        CType(sender, System.Windows.Forms.Form)
    Dim webBrowserOnPopup As EO.WebBrowser.WinForm.WebControl = _
        CType(popupForm.Controls.Item(0), EO.WebBrowser.WinForm.WebControl)

    'Call Destroy on the popup WebView
    webBrowserOnPopup.WebView.Destroy()
End Sub


The key is to call WebView.Destroy to explicitly destroy the WebView when the form closes. The reason is unless explicitly destroyed, the WebView is still kept in memory for 10 seconds in case your code needs it again. Because of this during this time if you click "Import" again, no NewWindow event will be raised since even though the WebView is not visible anymore, it is still alive. In this case the WebView's Activate event will be raised.

Thanks!

yleung
Posted: Sunday, June 22, 2014 1:12:10 PM
Rank: Advanced Member
Groups: Member

Joined: 4/2/2014
Posts: 37
Thanks.
That works well..
eo_support
Posted: Monday, June 23, 2014 10:38:30 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Glad to hear that it works for you! Please feel free to let us know if there is anything else.
onizerga
Posted: Sunday, February 19, 2017 11:55:15 PM
Rank: Newbie
Groups: Member

Joined: 2/10/2017
Posts: 5
Please give me for C# example

Thanks
eo_support
Posted: Monday, February 20, 2017 8:54:06 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
onizerga wrote:
Please give me for C# example

Thanks

We generally do not write code for specific scenarios for our customer. You can take a look of the TabbedBrowser sample application for C# sample code on how to handle NewWindow event, and you will need to understand the code in order to adapt it to fit your need. If you have any specific questions about any part of the sample code, please feel free to ask and we will be happy to help you further. But we do not do "this is what I need, please give me sample code to do this" type of support. We are here to help but in the end you will still need to write your own code.
Khoa
Posted: Monday, October 28, 2019 9:31:46 AM
Rank: Advanced Member
Groups: Member

Joined: 9/3/2014
Posts: 68
Here is the code to handle NewWindow event. But it does not work. The host window form is created with a WebControl with WebView inside. However, the page just immediately shows up then disappear. It seems the WebView is destroyed right after showing up its URL. Could you please explain why.

Code: C#
webView.NewWindow += (sender, e) =>
{
	e.Accepted = true;
	WebView webView2 = e.WebView; // Get newly created WebView
	webView2.LoadUrl(e.TargetUrl);
	// Create a new Form to host the web view
	var form = new Form
	{
		Size = new System.Drawing.Size(800, 600),
		StartPosition = FormStartPosition.CenterParent
	};
	var webControl2 = new EO.WinForm.WebControl
	{
		Dock = DockStyle.Fill,
		WebView = webView2
	};
	var nativeWindow = new NativeWindow();
	nativeWindow.AssignHandle(this.Handle);
	form.Controls.Add(webControl2);
	//form.ShowDialog(nativeWindow);
	form.Show(nativeWindow);
};


Thank you.
eo_support
Posted: Tuesday, October 29, 2019 9:55:20 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Hi,

You should NOT call LoadUrl(e.TargetUrl). The Url will be automatically loaded as soon as you accept the WebView.

Thanks!
Khoa
Posted: Tuesday, October 29, 2019 3:37:21 PM
Rank: Advanced Member
Groups: Member

Joined: 9/3/2014
Posts: 68
Thank you. A little code change to have it work:

Code: C#
webView.NewWindow += (sender, e) =>
{
	e.Accepted = true;
	// Get newly created WebView
	WebView webView2 = e.WebView;
	// Create a new Form to host the web view
	var form = new Form
	{
		Size = new System.Drawing.Size(800, 600),
		StartPosition = FormStartPosition.CenterParent
	};
	webView2.Closed += (sender2, e2) =>
	{
		form.Close();
	};
	var webControl2 = new EO.WinForm.WebControl
	{
		Dock = DockStyle.Fill,
		WebView = webView2
	};
	var nativeWindow = new NativeWindow();
	nativeWindow.AssignHandle(this.Handle);
	form.Controls.Add(webControl2);
	// Show the popup form
	form.Show(nativeWindow);
};


Thanks.
eo_support
Posted: Tuesday, October 29, 2019 3:53:18 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Great. Glad to hear that it's working!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.