Welcome Guest Search | Active Topics | Sign In | Register

Could not open NewWindowEventArgs.TargetUrl in the existing WebView. Options
anninkov
Posted: Monday, August 17, 2020 11:49:19 AM
Rank: Member
Groups: Member

Joined: 7/7/2017
Posts: 13
Hello, support!

I have created a WPF application that contains WebControl element (libraries version: EO.Total 20.2.19):

Code: XML
<eo:WebControl x:Name="WebControl">
    <eo:WebControl.WebView>
        <eo:WebView>
        </eo:WebView>
    </eo:WebControl.WebView>
</eo:WebControl>

WebControl loads some URL (customer card) in the code-behind successfully. In addition, I have subscribed to a NewWindow event that occurs when WebView opens a new window:

Code: C#
WebControl.WebView.NewWindow += WebViewNewWindowEventHandler;
...
if (!string.IsNullOrEmpty(_workplaceUrl))
{
    WebControl.WebView.LoadUrl(_workplaceUrl);
}

I would like to open the target url from NewWindow event args in the existing WebControl.WebView without additional window creating.

I tried two WebViewNewWindowEventHandler implementation:

Code: C#
private void WebViewNewWindowEventHandler(object sender, NewWindowEventArgs e)
{
    WebControl.WebView.LoadUrl(e.TargetUrl);
}

In this case, WebControl loads e.TargetUrl successfully. But before that, a dialog message appears stating that the new window may be blocked by the pop-up blocker.

Code: C#
private void WebViewNewWindowEventHandler(object sender, NewWindowEventArgs e)
{
    WebControl.WebView = e.WebView;
    e.Accepted = true;
}

In this case, the required webpage does not load within the browser element and I get a blank form.

Is there a correct way to open a webpage (NewWindowEventArgs.TargetUrl) in the main WebControl.WebView without displaying a dialog message?

Can you help me with this problem? Maybe it is something wrong in my logic?

Please advise.

Sincerely,
Dmitry.
eo_support
Posted: Monday, August 17, 2020 2:05:41 PM
Rank: Administration
Groups: Administration

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

You will not be able to achieve that because the message is not displayed by us. It's displayed by the JavaScript code in your page. The code in your page would most likely be something like this:

Code: JavaScript
var newWindow = window.open(targetUrl, ....);
if (!newWindow)
    alert("My popup has been blocked!");


Your choice is to either block the new window (so window.open returns null) or to block it. If you do not block it, your must "accept" the new WebView. If you block it, window.open will return null and the code in the page will be able to detect this.

Obviously unless you can change this code in your page, you can't have both. A "hack" is possible by handling the WebView's JSDialog event to silent the alert message but that's based on the assumption that the user code is using alert to display the message. They could use a completely different way to display you a message, then such hack would not work.

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.