Welcome Guest Search | Active Topics | Sign In | Register

WebBrowser: How to implement "Open in new tab/window" command? Options
Stefan Koell
Posted: Monday, October 25, 2021 6:39:02 AM
Rank: Advanced Member
Groups: Member

Joined: 12/23/2013
Posts: 114
Hi,

I checked the sample and the docs but I can't figure out what's the best way to implement a context menu command / modifier feature to open a clicked link in a new tab/window (handling the NewWindow event). Is there a way to implement that?

Regards,
Stefan
eo_support
Posted: Monday, October 25, 2021 5:29:06 PM
Rank: Administration
Groups: Administration

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

This question is actually not as easy as it seems. We will try to list out the key points here:

1. EO.WebBrowser does not have any idea of "tab". All it does is to maintain the WebView objects. When you have multiple WebView objects, it is your responsibility to arrange them on screen (or even off screen) however you want. For example, you can arrange them in an old fashioned MDI parent/child window setting, you can arrange them as "tiles" one next to each other; or most commonly, you can employ a tabbed interface and put one WebView in each tab ---- the key here is this tabbed UI interface is your interface. The browser engine does not know/care anything about it.

2. NewWindow event is triggered when a new WebView is internally created by an "opener" (with the new WebView's window.opener set to the WebView that triggered the creation of the new WebView). A typical scenario that triggers NewWindow is when you have an A element with a target attribute or call window.open method in JavaScript code. Again, this has nothing to do with tab --- even though most commonly the UI implementation would choose to display the new WebView in a new tab. The key about this event is not tab, the key about this event is the two WebViews are linked together through window.opener property;

3. The TabbedBrowser sample application does use tabs. However based on #1 and #2, this is purely TabbedBrowser sample application's choice. It has nothing to do with EO.WebBrowser product. The TabbedBrowser sample application uses the TabControl/DockView control provided by EO.Wpf to implement the tabs. So if you do not plan to use EO.Wpf, you would use a different tab solution. And exactly how to add tab would depend on whatever tab solution you use;

4. It is possible for you to use JavaScript code to convert a normal link to a call to window.open method (by handling the A element's onclick event and then call window.open inside that event handler). This would trigger case #2. However currently it is not possible for you to do this through context menu. Even though you could follow #3 to add a new tab in your UI and then load the Url in that tab, this would not establish the window.opener relationship as in #2;

Hope this helps and your head is not spinning yet. :)

Thanks

Stefan Koell
Posted: Wednesday, October 27, 2021 5:53:45 AM
Rank: Advanced Member
Groups: Member

Joined: 12/23/2013
Posts: 114
Thanks for the detailed response! It was very helpful. I was able to successfully implement the Open in new Tab command.
eo_support
Posted: Thursday, October 28, 2021 2:02:47 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Great. Glad that it helped.


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.