Welcome Guest Search | Active Topics | Sign In | Register

winform WebBrowser NewWindow event, Referer url Options
macgyber
Posted: Thursday, July 9, 2020 10:46:51 AM
Rank: Newbie
Groups: Member

Joined: 6/10/2020
Posts: 4
dotnet EO.WebBrowser - NewWindow is being tested.
Of course I saw the Tabbed Browser Demo.

But the xaml format is too difficult for me.

I'm on page1 and page2 of the windows default tab control on form1.
Webview1 and Webview2 have been configured in advance.

Simply click on the link in the new window of Webview1...
I want to display the newly opened url in webview2.

However, I would like to bring the Referer (url) of Webview1,
other cookies, and form data intact. When you simply click on the new window link
I would be grateful if you could show me how to easily pass that link to webview2.
eo_support
Posted: Thursday, July 9, 2020 10:57:39 AM
Rank: Administration
Groups: Administration

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

You should not do this. NewWindow let you open a new WebView, so if you do not open a new WebView (in your case you want to populate an existing one WebView2), then you would change the behavior of the corresponding JavaScript side call and can cause problems for you.

For example, if the JavaScript code in WebView1 is:

Code: JavaScript
var wnd = window.open("", "test", "width=200,height=100");
wnd.document.write("Hello");


Then this code will fail when you handle NewWindow the way you described. The first line will return null and the second line will cause an exception.

You can read more details about how to handle NewWindow event here:

https://www.essentialobjects.com/doc/webbrowser/advanced/new_window.aspx

The key is you should NOT have your own WebView2. You must accept the new WebView passed to you through the event argument and display that WebView somewhere. Exactly how to display it is platform dependent. This is part is where WPF is used in the sample app. If you do not use WPF, you can simply ignore that part and display it however you do it in your Windows Forms application.

Hope this helps.

Thanks
macgyber
Posted: Thursday, July 9, 2020 11:30:14 AM
Rank: Newbie
Groups: Member

Joined: 6/10/2020
Posts: 4
Thank you for the prompt response.
But it's still very difficult.
If possible, use only C# winform
I would like source and example using basic tab control.
Thank you.
eo_support
Posted: Thursday, July 9, 2020 11:57:02 AM
Rank: Administration
Groups: Administration

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

You can follow these steps:

Step 1:
Write code to do this inside NewWindow event handler:
1. Create a new tab;
2. Create a new Button inside that tab;
3. Display that tab (set it to active);

After this step when you try to open a new window in WebView, your code would open a new tab and display a new Button in that tab. This step is where different user may choose to do things very differently. For example, you wanted to display a new tab, another user may wanted to display a completely new Form.

Step 2:
Replace the Button control with EO.WinForm.WebView control. For example, if the code in step 1 is:

Code: C#
Button button = new Button();

Then you replace it with:

Code: C#
EO.WinForm.WebControl webControl = new EO.WinForm.WebControl();


Step 3:
Set the WebControl's WebView to e.WebView:

Code: C#
webControl.WebView = e.WebView;


To summarize, these steps together does:

1. Create a new tab (as you wished);
2. Create a new WebControl inside that tab;
3. Hand e.WebView over to this WebControl to display;

We generally do not provide code for you to copy and paste, especially for generic programming task such as step 1 because you need to understand how the code works in order to use our product effectively. If you have any problems understanding any of these steps please feel free to ask, but in the end you must be able to write your own code.

Thanks!




macgyber
Posted: Thursday, July 9, 2020 12:46:54 PM
Rank: Newbie
Groups: Member

Joined: 6/10/2020
Posts: 4
Oh now I understand a little. thank you so


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.