0
votes

I'm using the WebView control in a Metro app. I'd like to implement a "Back" button function, but can't seem to locate an inbuilt one. Can anyone tell me if there is one, or do I need to roll my own (admittedly not the most complex coding task, but I don't want to reinvent the wheel)?

3
Where would you like to add the back button inside or outside the WebView? Either way you will need roll your own.sarvesh

3 Answers

3
votes

This worked for me:

webView.InvokeScript("eval", new[] { "history.go(-1)" }); 
1
votes

Unfortunately you will have to roll your own. You should be able to use something like:

webView.InvokeScript("history.back();");

or possibly

webView.InvokeScript("history.go(-1);");
1
votes

The suggested code works. Here it is more complete:

in the xaml

    <Button Content="Back" HorizontalAlignment="Left" Margin="580,98,0,0"   VerticalAlignment="Top" Click="Button_Click_1"/>

in the xaml.cs

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        webView.InvokeScript("eval", new[] { "history.go(-1)" }); 
    }