Refresh / Reset page

Hi I am only new to this stuff, I am having some trouble with a webview… When I navigate to the page with a webview the last viewed webpage still shows. Is there any way to reset it on open so it always shows the initial webpage upon navigation?

Hi Jason,

please include some code to show what you’ve tried so far, and to better illustrate the challenge you’re facing.

Hi Uldis.

I use the following function to navigate to the page with a webview

   function fb_timeline_go(arg) {
        var subCat = arg.data;
        router.push("fb_timeline", subCat);
    }

The following is the page with the webview…

<NativeViewHost Width="100%" ux:Class="fb_timeline">
	<Router ux:Dependency="router" />
	<WebView Width="100%" Margin="0,56,0,0">
		<HTML>
			<![CDATA[<html><head><meta name="viewport" content="width=device-width, initial-scale=1.0"></head><body><a href="google.com">Google</a></body></html> ]]>
		</HTML>
	</WebView>
</NativeViewHost>

The webview contains a link to Google. If I click that link it will go to Google. One issue I have is when I press the back button instead of navigating back a webpage it navigates back an app page instead… and then when I navigate forward to the webview again it continues to display Google… I’m hoping for it to show the initial link again.

Thanks for your help.

Okay, so there are two questions. The first one is about resetting a page after you’ve navigated away from it. This was recently answered in another forum thread. Be aware that using Reuse="None" may cause performance issues, since pages in a given Navigator wouldn’t be reused; prefer setting it on a single page, if absolutely necessary.

The other question is about navigating within a WebView on Android back button. For this, I can provide a little snippet that shows how you can go about intercepting the back button click, and reacting on it depending on if the WebView has navigation history or not. This could also be coupled with a “soft” back button that you’d need on iOS, by using UserEvent.

Hope this helps!

<Panel ux:Class="SomePage">
    <Router ux:Dependency="router" />

    <WhileCanGoBack NavigationContext="webView" Invert="true">
        <OnBackButton>
            <GoBack NavigationContext="router" />
        </OnBackButton>
    </WhileCanGoBack>

    <WhileCanGoBack NavigationContext="webView">
        <Change router.BackButtonAction="None" />
        <OnBackButton>
            <GoBack TargetNode="webView"/>
            <Reload TargetNode="webView"/>
        </OnBackButton>
    </WhileCanGoBack>

    <NativeViewHost>
        <WebView ux:Name="webView" Url="https://www.google.com/" />
    </NativeViewHost>
</Panel>

Worked perfectly, thank you so much.