Welcome Guest Search | Active Topics | Sign In | Register

Web Browser target="_blank" does not work Options
Rick Morayniss
Posted: Thursday, January 22, 2015 9:16:19 AM
Rank: Advanced Member
Groups: Member

Joined: 12/30/2013
Posts: 68
In my app that is being converted, I have a number of handbook and videos that are seen by the user.

When the user clicks on the download button inside your webbrowser control,
A new window/page is not created instead a popup message
"The current page is tries to open a new window. Please handle NewWindow event."
This is not a deprecated browser issue, It is nothing more then opening up a file in a new page.
Here is the code I am using.

<a target="_blank" href="02 - Sample Help file.pdf">download</a></td>
eo_support
Posted: Thursday, January 22, 2015 12:23:22 PM
Rank: Administration
Groups: Administration

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

You need to do exactly what the message says: handling NewWindow event. The difference between EO.WebBrowser and a traditional web browser is EO.WebBrowser is just the engine part, whereas the "frame" that the engine sits on are to be provided by you. On the other hand, a traditional "real" web browser has both parts.

When a link with a different target is clicked, the browser engine notifies you that a new "window" is being opened (through NewWindow event). However exactly how you want to open that new window is up to you. Your code can choose to ignore it (thus have the same effect as "popup blocker"), or can display it in a new tab, or can display it in a new dialog, etc. Or you might want to implement complex logic, for example, only allow popup from a certain list of hosts. Whatever way you want to do it is up to you and different users might want to handle it different ways. This is the why you must handle this event to do exactly what you want to do there. The actual code can be very simple: For example, if you want to implement a popup blocker, you simply handle the event but leave the event handler empty. If you want to display the new page is a Form, you simply create a new Form, place the new WebView inside the form and show it. You can find details about this event here:

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

You can also take a look of the TabbedBrowser sample to see sample code of how this is handled. The sample code is for WPF, however the idea is exactly the same. There are additional comment in the sample code that you might find to be useful as well.

Hope this answers your question. Please feel free to let us know if you still have any more questions.

Thanks!
Rick Morayniss
Posted: Thursday, January 22, 2015 3:19:22 PM
Rank: Advanced Member
Groups: Member

Joined: 12/30/2013
Posts: 68
Sorry, but I am a little confused.
I have initialized
private void webView1_NewWindow(object sender, EO.WebBrowser.NewWindowEventArgs e)
{
}
In your sample code in wpf, you have
//The new WebView has already been created (e.WebView). Here we
//associates it with a new WebViewItem object and creates a
//new tab button for it (by adding it to m_Pages)
WebViewItem item = NewWebViewItem(e.WebView);
m_WebViewsHost.Items.Add(item);
m_Pages.Add(item.Page);

//Select the newly created tab
mainTabs.SelectedIndex = m_Pages.Count - 1;

//Signifies that we accept the new WebView. Without this line
//the newly created WebView will be immediately destroyed
e.Accepted = true;

But since I am not using wpf, this makes no sence to me.
I do not have the class WebViewItem that you have in the sample as a wpf wrapper.

This should not be that difficult, All I am trying to do is open the new page in a new tab/page.
eo_support
Posted: Thursday, January 22, 2015 3:46:08 PM
Rank: Administration
Groups: Administration

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

You need to:

1. Create a new Form (or whatever container, such as a TabPage);
2. Create a new WebControl, set the new WebControl's WebView to the new WebView;
3. Place the new WebControl inside the new Form;

The code will be something like this:

Code: C#
//Create a new Form. You can replace this with
//another container control
Form form = new Form();

//Create a new WebControl. This is the bridge between
//Windows Form and WebView. 
EO.WebBrowser.WinForm.WebControl webControl = new EO.WebBrowser.WinForm.WebControl();

//Set the WebControl to fill its parent
webControl.Dock = DockStyle.Fill;

//Set the WebControl to host the new WebView, which
//is created by the browser engine when user clicks the
//link. You must use e.WebView, you can not create your
//own WebView here
webControl.WebView = e.WebView;

//Add the WebControl into the Form
form.Controls.Add(webControl);

//Display the form
form.Show();


Hope this makes sense to you.

Thanks!
Rick Morayniss
Posted: Thursday, January 22, 2015 4:02:45 PM
Rank: Advanced Member
Groups: Member

Joined: 12/30/2013
Posts: 68
That makes a lot more sense to me, thank you.
I do not understand why the webpage I am calling does not load.
I have tried both
webControl.WebView.Url = e.TargetUrl;
and
webControl.WebView.LoadUrl( e.TargetUrl);
before the control is added to the form( form.Controls.Add(webControl);)
I get a blank open form.

eo_support
Posted: Thursday, January 22, 2015 4:15:10 PM
Rank: Administration
Groups: Administration

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

Did you set e.Accepted to true? You do not need to set the new WebView's Url in your code. The browser engine will set it for you once the control returns from your code (your NewWindow handler) to the browser engine. However you must explicitly set e.Accepted to true if you wish the browser engine to continue loading.

Thanks!
Rick Morayniss
Posted: Friday, January 23, 2015 7:58:37 AM
Rank: Advanced Member
Groups: Member

Joined: 12/30/2013
Posts: 68
That is perfect, thank you.
I would like to suggest since most people do not use MVC, that you convert your sample projects (for me the webbrowser) into ASP.NET project (non MVC).

Thank you again for your time in helping me with my issues.
Rick Morayniss
Posted: Friday, January 23, 2015 8:43:01 AM
Rank: Advanced Member
Groups: Member

Joined: 12/30/2013
Posts: 68
It appears I was a little premature in my thank yous.
While the PDF's open and view perfectly, the mp4's do not. I get a save message, then a blank screen.
I ran the same test in your tab browser example, (logged into my test site, went to the page where the links are and clicked on the link for 1 of the mp4s.)
I got the same result.Just a blank page. The video did not run.


eo_support
Posted: Friday, January 23, 2015 10:37:34 AM
Rank: Administration
Groups: Administration

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

You need to call EO.WebBrowser.Runtime.AllowProprietaryMediaFormats in order to support MP4. See here for more details:

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

You can call this in your Main function before starting anything else.

Thanks!
Rick Morayniss
Posted: Friday, January 23, 2015 11:06:50 AM
Rank: Advanced Member
Groups: Member

Joined: 12/30/2013
Posts: 68
Thank you for the reply. Unfortunately that did not work.
I am sending my initializing function for the application.
Please let me know what I am doing wrong.

public frmMain()
{
InitializeComponent();
EO.WebBrowser.Runtime.AllowProprietaryMediaFormats();
EO.WebBrowser.Runtime.AddLicense( "This is where my license goes");
try
{
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

}
catch (Exception ex)
{
//manage also these exceptions
}




}
eo_support
Posted: Friday, January 23, 2015 1:42:47 PM
Rank: Administration
Groups: Administration

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

Try to call it in your Program.Main method. You need to do it before everything else --- even before your frmMain is created. A typical C# Windows Form program has a Program.cs that contains a Main method that calls Application.Run(new Your_Main_Form()). Make sure you call AllowProprietaryMediaFormats before that.

If that still doesn't work, then you can try to isolate the problem into a test project and send the test project to us. We will be happy to take a look once we have that. You can find instructions on how to send a test project to us here:

http://www.essentialobjects.com/forum/test_project.aspx

Thanks!
Rick Morayniss
Posted: Tuesday, January 27, 2015 8:53:26 AM
Rank: Advanced Member
Groups: Member

Joined: 12/30/2013
Posts: 68
That solved the issue.
Thank you for your help.
eo_support
Posted: Tuesday, January 27, 2015 11:08:49 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
You are very welcome. Please feel free to let us know if there is anything else.

Thanks!


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.