0
votes

i need some advice for handling a Stop function for my browser. it must be caused by a buttonclick, so i think i will need javascript to solve this problem. Somebody already faced this issue?

greets roqstr

2
What exactly do you mean by "stop"? - Pekka
if you're trying to stop navigation inside a webbrowser, just override Navigating after the initial page you want has LoadCompleted, and e.Cancel the NavigationArgs. - William Melani
@willmel: is it possible to access the active "navigating" method, to set a e.cancel = true? - roqstr
@Pekka i want to cancel the active navigation-process - roqstr

2 Answers

0
votes
public MainPage()
        {
            InitializeComponent();

                //wb is the webbrowser
                wb.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(wb_LoadCompleted);

//pretty sure you need this somewhere other than the constructor, or you'll get that 
//"cannot navigate until in visual tree" exception
wb.NavigateToString(MyHTMLString);
            }

        void wb_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            wb.Navigating += new EventHandler<NavigatingEventArgs>(wb_Navigating);
        }

        void wb_Navigating(object sender, NavigatingEventArgs e)
        {
            e.Cancel = true;
        }

The idea is basically that. override LoadCompleted, and after the page you want to load loads, make sure that no other page can be navigated to by setting e.Cancel inside the Navigating event.

0
votes

what's working fine:

private void cancel_Click(object sender, MouseButtonEventArgs e)
    {
       browser.InvokeScript("eval", "document.execCommand('Stop');");
    }

thanks for your effort.