none
How to Block Popup in WPF 3.5 WebBrowser Control.?

    Question

  • Hello Guys, How I can Block PopUp window in WPF 3.5 same as NewWindow

    Basically my problem is I have WPF 3.5 WebBrowser and I want to handle Pop Up Windows so the Pop Up window doesn't allow to subscribe any event like navigated so how I can hadle this Pop Up window Because we are using kios base application there is no WebBrowser if user can click any of the Hyperlink and the Pop Up will crash the system so I want to handle this Pop Up window.

    eg. I have Facebook application once user click into the Sing up for Facebook that time it will Pop Up window I want to handle this window.?

    Thank you..!


    Jitendra Jadav

    • Edited by Jitendra Jadav Monday, January 16, 2012 12:12 PM modify for more clerification
    Monday, January 16, 2012 10:07 AM

All replies

  • Hi Jitendra, I hope you're fine.

    May you, please, elaborate a little bit, give an example or write a segment of code to clarify the issue more to help people provide a precise and clear answer.

    Many thanks for your understanding.


    Please, mark my reply as Answer if it helps or vote it up if it gives a key to the solution.
    Thanks in advance and good luck.
    Ahmed M. Gamil
    "It is not titles that honor men, but men that honor titles."
    Monday, January 16, 2012 11:27 AM
  • Dear @Gmil I have added some more Clerification so you can check this my question thank you.!

     


    Jitendra Jadav
    Monday, January 16, 2012 12:13 PM
  • Well mate, I have the following two links:

    1. http://stackoverflow.com/questions/219817/curious-pop-up-behavior-when-using-webbrowser-class

    2. http://stackoverflow.com/questions/6424811/help-can-i-stop-wpf-webbrowser-popups

    I hope they help.


    Please, mark my reply as Answer if it helps or vote it up if it gives a key to the solution.
    Thanks in advance and good luck.
    Ahmed M. Gamil
    "It is not titles that honor men, but men that honor titles."
    Monday, January 16, 2012 12:53 PM
  • Well mate, I have the following two links:

    1. http://stackoverflow.com/questions/219817/curious-pop-up-behavior-when-using-webbrowser-class

    2. http://stackoverflow.com/questions/6424811/help-can-i-stop-wpf-webbrowser-popups

    I hope they help.


    Please, mark my reply as Answer if it helps or vote it up if it gives a key to the solution.
    Thanks in advance and good luck.
    Ahmed M. Gamil
    "It is not titles that honor men, but men that honor titles."


    Thank you very much for you reply but could you explain me how I can use the send step which is related to the script so I dont know how to handle this script into XAML even I have tried this but I couldn't succsess if you will help me that will be greately appreciate!!

    this script like this

    var d = document.getElementsByTagName('a');
    for (var i = d.length-1; i > -1; i--) {
    if (d.getAttribute('target') == "_blank") {
    d.removeAttribute('target');
    }
    }
    

    I mear where I can add this script XAML or codebehind. I have added into the CodeBehind and it will give me error like document is unknown and all. so can you specify.

    once again thank you..!!


    Jitendra Jadav
    Monday, January 16, 2012 1:19 PM
  • this method can resolve your issue:

    http://stackoverflow.com/questions/77659/blocking-dialogs-in-net-webbrowser-control

    http://stackoverflow.com/questions/153748/how-to-inject-javascript-in-webbrowser-control

     


    Stay hungry, stay foolish


    Thank you @Helper my problem still open because wpf 3.5 is not support to manny things:

    1. from where I can call this function(I have tried with  Contruction and also Navigated event but I couldn't success) it is not fired.

    2. It doesn't suport myWebBrowser.Document.GetElementsByTagName

     

    so these are the problems how I can hadle this issue even I have spent good amount of time but i didn't success can you help me..!

    thank you..

     

     


    Jitendra Jadav
    Tuesday, January 17, 2012 11:07 AM
  • If you want to stop popups the best way is to use the winforms webbrowser.  It is the same as the WPF webbrowser with much more functionality.

    The following is a sample XAML file using the winforms webbrowser.

    <Window x:Class="SupressPopUp"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        Title="SupressPopUp" Height="300" Width="300" Loaded="Window_Loaded">
        <Grid>
            <WebBrowser x:Name="theBrowser" ></WebBrowser>
            <WindowsFormsHost>
                <wf:WebBrowser NewWindow="WebBrowser_NewWindow"></wf:WebBrowser>        
            </WindowsFormsHost>
        </Grid>
    </Window>
    
    

    The following is the code (VB.NET) to suppress popups.

        Private Sub WebBrowser_NewWindow(sender As System.Object, e As System.ComponentModel.CancelEventArgs)
            e.Cancel = True
        End Sub
    
    


    Hope this helps

    Lloyd Sheen


    Lloyd Sheen
    Tuesday, January 17, 2012 3:06 PM
  • If you want to stop popups the best way is to use the winforms webbrowser.  It is the same as the WPF webbrowser with much more functionality.

    The following is a sample XAML file using the winforms webbrowser.

     

    <Window x:Class="SupressPopUp"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        Title="SupressPopUp" Height="300" Width="300" Loaded="Window_Loaded">
        <Grid>
            <WebBrowser x:Name="theBrowser" ></WebBrowser>
            <WindowsFormsHost>
                <wf:WebBrowser NewWindow="WebBrowser_NewWindow"></wf:WebBrowser>        
            </WindowsFormsHost>
        </Grid>
    </Window>
    
    

     

    The following is the code (VB.NET) to suppress popups.

     

        Private Sub WebBrowser_NewWindow(sender As System.Object, e As System.ComponentModel.CancelEventArgs)
            e.Cancel = True
        End Sub
    
    

     


    Hope this helps

    Lloyd Sheen


    Lloyd Sheen


    First of all I would like to say thak you very much. but one problem from my side is there How I can implement into the MvvmLight application because I had tried with normal application and it would be work perfectly. but in my case I have MvvmLight application so

    I could not find the <wf:WebBroser/> if I can add into the UserControl.Resources then it will appear but how I can add into the my actual grid is there any idea.

    Once again thanks...!


    Jitendra Jadav
    Tuesday, January 17, 2012 4:41 PM
  • I have never used MVVM (don't really like frameworks) so I can't help you there.

    When you say you cannot find the wf:WebBrowser what do you mean?

    LS


    Lloyd Sheen
    Tuesday, January 17, 2012 5:00 PM
  • I have never used MVVM (don't really like frameworks) so I can't help you there.

    When you say you cannot find the wf:WebBrowser what do you mean?

    LS


    Lloyd Sheen

    I mean I found into the UserControl.Resources but if I can use this same into the regular control it will not allow to inherit the wf:WebBrowser because we are using MvvmLight.?
    Jitendra Jadav
    Wednesday, January 18, 2012 7:33 AM
  • Hello Guys, How I can Block PopUp window in WPF 3.5 same as NewWindow

    Basically my problem is I have WPF 3.5 WebBrowser and I want to handle Pop Up Windows so the Pop Up window doesn't allow to subscribe any event like navigated so how I can hadle this Pop Up window Because we are using kios base application there is no WebBrowser if user can click any of the Hyperlink and the Pop Up will crash the system so I want to handle this Pop Up window.

    eg. I have Facebook application once user click into the Sing up for Facebook that time it will Pop Up window I want to handle this window.?

    Thank you..!


    Jitendra Jadav

    Hello Guys, How I can Block PopUp window In AxWebBrowser1 but still problem faces so what can i do for proper solution
    Friday, February 17, 2012 1:00 PM
  • you can simply take your wpf web browser in WindowsFormsHost control and then in Constructor you can set the ScriptErrorsSuppressed property true for Blocking Pop ups .
    Saturday, July 21, 2012 6:03 AM