Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to do "Stop" "Back" and "Forward" with webbrowser in WP7? [duplicate]

I am using a web-browser in my windows phone 7 application. I just want to know that how to handle its back and forward navigation just like any desktop browser. And also how to block a particular navigation.

I referred here and many others but couldn't find anything working for me. Please help.

like image 650
Mahima Gandhe Avatar asked Nov 25 '22 05:11

Mahima Gandhe


2 Answers

You can cancel navigation by handling the OnNavigating event

private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
    //cancel navigation
     e.Cancel = true;

}

To go back, you can execute javascript on the page.

webBrowser.InvokeScript("eval","history.go(-1)");

and move forward:

webBrowser.InvokeScript("eval","history.go(1)");

If eval is blocked on the page, this site might be useful for alternatives. Don't forget to set webBrowser.IsScriptEnabled to true.

like image 199
keyboardP Avatar answered Nov 27 '22 19:11

keyboardP


To make it work like a desktop browser you can implement a stack.

You will put two buttons back and forward. As the user navigate to next URL in browser you push them into history stack and when he wants to get back by pressing back button you navigate to the first url in the history stack programmatically and pop it up from the history stack so he can navigate back till stack has some URLs in it. Similarly for forward you push URLs into forward stack as he navigates back and and whenever he presses forward button you navigate to first element in forward stack and pop it up and so on till you have urls left in forward stack. Once he navigates to some url which is not navigated from forward stack by you then you empty the forward stack and fill it again when he moves back.

This way you can even show history urls in a list or however you like.

About navigation cancel, here is the code from the link to question in the comments under your question, it should work.

private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
    //cancel navigation
     e.Cancel = true;

}
like image 40
parveenkhtkr Avatar answered Nov 27 '22 18:11

parveenkhtkr