Skip to main content
Home Forums General Silverlight New Features in Silverlight 3 Intercept back and forward buttons
5 replies. Latest Post by AustinLamb on July 1, 2009.
(0)
TomGiam
Participant
788 points
220 Posts
06-28-2009 4:17 PM |
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:
but, I'm not getting the Navigating event when I click on the buttons.
Thanks
Tom
dpatra
Member
22 points
20 Posts
06-29-2009 2:47 AM |
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
06-29-2009 1:10 PM |
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)
figuerres
264 points
111 Posts
06-29-2009 6:27 PM |
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....
07-01-2009 11:11 AM |
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.
AustinLamb
602 points
104 Posts
07-01-2009 7:21 PM |
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.