Paul Michaels
Paul Michaels

Reputation: 16695

WinRt WebView "Back Button"

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)?

Upvotes: 0

Views: 1883

Answers (3)

Eric Boehlke
Eric Boehlke

Reputation: 81

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)" }); 
    }

Upvotes: 1

Jared Bienz - MSFT
Jared Bienz - MSFT

Reputation: 3550

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);");

Upvotes: 1

Ferro
Ferro

Reputation: 2182

This worked for me:

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

Upvotes: 3

Related Questions