Intercepting urls in Windows Phone Browser - windows-phone-7

In my app I have two pages: Main Page and Display Page. Each page has a browser control.
On Main Page the source of the browser control is set to a website's homepage. If the user touches a thumbnail, I want it to be shown on Display Page.
How do I grab the address of the link that has been clicked/touched and send it to the browser on Display Page?

WebBrowser control has Navigating and Navigated Events.
In the Navigating handler, you can get the clicked link as e.Uri. get that and cancel the Navigation. then send that link to Display page.
void web_Navigating(object sender, NavigatingEventArgs e)
{
e.Cancel = true;
NavigationService.Navigate(new Uri("/DisplayPage.xaml?TargetUri="+e.Uri.ToString(), UriKind.Relative));
}
Note: By the way, sending the e.Uri is not a suggestible way. I would suggest you create a Static propety in the project and use that for sharing the links among pages.

Related

Replace Xamarin forms page without pushasync

I've searched through numerous online posts and can't find a suitable answer for this scenario. It's a pretty common requirement. I have a Xamarin.Forms app with a login page and listing page. When the app is started, the login page is displayed. When they login successfully, I want to display the listing page and prevent them from backing up by clicking on the toolbar back button or the hardware back button.
Change the MainPage
when you start the app you should have
Application.Current.MainPage = new LoginPage();
after login, something like
Application.Current.MainPage = new MyFirstPageAfterLogin();

Disallow closing Rg Plugin popup in Xamarin Forms

I am using Rg Plugin popup for popup in Xamarin Forms application. I would like to disallow user from closing this popup. After some time, application will close this popup. Is it possible?
Why I need this: When user opens application for the first time, I would like to show usual start page and on top of it popup. Both are visible: in the middle there is popup and around it usual start page with grey overlay. In popup progress bar will be displayed while fetching data from server. User should not be able to close this popup. When fetching data is over, I would like to refresh start page and close this modal.
As Dinesh kumar pointed out, 2 things need to be done - to disallow clicking on background and to disallow back button:
public MyPopup()
{
InitializeComponent();
CloseWhenBackgroundIsClicked = false;
}
protected override bool OnBackButtonPressed()
{
return true; // Disable back button
}

WP7 conditional start page

I know I can set up start page in WMAppManifest.xml file.
Is there a way to set start page based on some condition?
I have an application that have 'remember me' funcionality so when app starts I would like it to go directly to some page. If user is not remembered then show log in screen.
Now I show a page and in it's logic I check this and if necessary I navigate to other page.
Is there a better way to do this?
Thanks,
Bartek
From this page, in your App.xaml.cs:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
Uri nUri = new Uri("/Page1.xaml", UriKind.Relative);
((App)Application.Current).RootFrame.Navigate(nUri);
}
Then open your WMAppManifest.xml file and clear the NavigationPage from the DefaultTask line.
<DefaultTask Name ="_default" NavigationPage=""/>
Have you seen this "WP7 - Dynamically change the startup page depending on setting":-
WP7 - Dynamically change the startup page depending on setting
I dont know of any better ways of conditionally redirecting to different pages other than having a loading page which checks and does the redirect for you.

webBrowser control won't redirect although IE 9 Mango does

I have a a link that redirects to another. The destination link is a link to a video.
The problem is that i can't get the destination link because the WebBrowser doesn't redirect to it. When i use IE9 with my initial link, it redirects me to the desired link, but when i use a WebBrowser control, using the same initial link, it doesn't do nothing. How can i enable this?
(i.e. the WebBrowser has the isScriptEnabled true) .
The webservice that i use is user-agent sensitive(it gives video for diferent devices) but it isn't mean for non-browser usage, so this is probably the issue.
Because HttpWebRequest and WebClient don't render pages (so i can't redirect to the page i want) i need to use a webBrowser. Parsing the response for that request isn't a solution(no data usable in the response so that i can get the redirect link)
I have seen the web browser control fail to redirect on a few occasions. What I did was just look for the meta tag myself, and then redirect to the page manually. It is by no means pretty, but it works
Recently encountered with the same issue while implementing facebook registration logic via embedded webcontrol. My solution was to redirect to the same page again, the code
void browser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
// TODO FIX HACK
// sometimes web browser does not redirect to callback url during facebook authentication
// so we refresh the page
if (e.Uri.ToString().StartsWith(#"https://www.facebook.com/dialog/permissions.request") &&
browser.SaveToString().Contains("window.location.href=\"http:\\/\\/www.facebook.com\\/connect\\/login_success.html"))
{
browser.Navigate(e.Uri);
}
}

AJAX webpage to navigate on previous page

The data is displayed in gridview with paging on an AJAX enabled webpage. The gridView contains Item templates containing a link button. On itemCommand event, page redirects to display data in new page. When the Back button on browser is pressed, the previous state of the page doesn't load.
Perhaps set a cookie and use it to get the right page when initializing the gridview. Or modify the hash at the end of the URL (eg, add "#page2" to the location bar and read it back on init).
Look at this js stuff from google
Use Google Web Toolkit, it allows the state to be bookmarked and isn't affected by back/forward button.
Otherwise your options are:
Telling the user to not press the back button.
Putting the state in the url, e.g mypage.asp#page_123 and using that to determine the state in your javascript at page load.

Resources