Skip to main content

Microsoft Silverlight

Answered Question Intercept back and forward buttonsRSS Feed

(0)

TomGiam
TomGiam

Member

Member

706 points

204 Posts

Intercept back and forward buttons

Is there a way to Intercept the back and forward buttons and then prompt the user if they really want to and then perform the action?

I don't really use navigation in my app, this is an attempt to warn them that they are leaving my app.

I created a navigation frame around my layout grid like this:

<nav:Frame x:Name="frame" JournalOwnership="UsesParentJournal" Navigating="Frame_Navigating">

but, I'm not getting the Navigating event when I click on the buttons.

Thanks

Tom

 

dpatra
dpatra

Member

Member

22 points

20 Posts

Re: Intercept back and forward buttons

Hi Tom,

 I guess the following code helps you. :)

 

1    private void NavButton_Click(object sender, RoutedEventArgs e)
2            {
3                MessageBoxResult mbr;
4                mbr= MessageBox.Show("Do you want to Navigate?", "Navigation", MessageBoxButton.OKCancel);
5                if (mbr==MessageBoxResult.OK)
6                {
7                    Button navigationButton = sender as Button;
8                    String goToPage = navigationButton.Tag.ToString();
9                    this.Frame.Navigate(new Uri(goToPage, UriKind.Relative));
10               }
11           }
12   

 

Thanks :)

Diptimaya

Thanks
Diptimaya Patra

Please remember to mark the replies as answers if they help

TomGiam
TomGiam

Member

Member

706 points

204 Posts

Re: Intercept back and forward buttons

My first problem is that I'm not getting an event when the Back or Forward button from the browser is pressed.

The second problem is that I need to be able to allow/disallow a "Back" or read the history and perform a back.

 I'm not sure if the navigation framework allows this.  I may need some kludge or javascript or just open a new window so that there is no history.

My only concern is the "Back" button. since the Forward will be disabled (nothing to go to)

Thanks

Tom

 

figuerres
figuerres

Member

Member

248 points

106 Posts

Re: Re: Intercept back and forward buttons

PLEASE LEAVE THE BROWSER ALONE!

i can't count how many times i have hit pages that muck with the browser back button and make it a total pain in the a$$ to try and browse back....

if the user hits the button then they get what they asked for.  and you can not always count on client side javascript working.... or working right....

TomGiam
TomGiam

Member

Member

706 points

204 Posts

Re: Re: Intercept back and forward buttons

Perhaps we need a feature that launches the SL application directly in OOB mode.

Kind of like click once applications, but cross platform.

The browser is just a means to get to a SL application.  After the SL application is launched the browser is unnecessary.

SL (and RIA in general) brings a paradigm shift in which we have web launchable applications and not web pages.  Once in the application, the application contains all of the necessary navigation so the back and forward buttons are unnecessary.

We should not sacrifice innovation and ease of use just to maintain the hack which is HTML based applications.

 

Tom

 

AustinLamb
AustinLamb

Member

Member

602 points

104 Posts

Microsoft
Answered Question

Re: Intercept back and forward buttons

Hi Tom,

You mention you're not receiving the Navigating event when the browser's back/forward button has been pressed.  This event should be getting raised - can you perhaps post a repro project and details on what browser/OS you're using when you don't get Navigating?

You won't be able to completely disable the browser's Back button (which is a good thing - imagine a malicious app that prevents you from leaving the app unless you close the browser).  But you could (if you really want to) hook into the JavaScript "onbeforeunload" event and prompt the user to tell them they're about to leave the app.  The browser will give them OK/Cancel buttons, and (if I'm remembering this correctly - I may have it backwards) OK will still leave the app, but Cancel will remain on the app.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities