Metro App handle open link / url loading in webview - c#

i have a banner which contain click zone to url like this :
playMusic://123456
How can i catch link opening or url loading for manage this type of link into the application?
it seems that there is no webview event for this, and I have not managed to find a override method.
Thanks.

I hope that your webview dynamically changes the url, and you need to catch the dynamically navigated url.
If so,
WebView1.LoadCompleted += WebView1_LoadCompleted;
void WebView1_LoadCompleted(object sender, NavigationEventArgs e)
{
new MessageDialog(e.Uri.ToString()).ShowAsync();
}
This code will display Message Box of the url loaded when webview navigated to an url...
If this is not you looking for, pls elaborate your scenario ..

Related

Action when website changes

how can i make action when link in WebBrowser1 changes?
I tried to do if(webbrowser1 == https://www.google.nl/intl/en/about/)but it doesn't work
I mean at startup in WebBrower1 is http://www.google.com and when i click something in this WebBrowser1 link changes, for example https://www.google.nl/intl/en/about/ and my question is, how can make an action (MessageBox.Show("you are here"); when i'm on main google page and i'm go to about page
This is "Windows Forms Application"
I guess you could do it using Navigated event.
You can also find an example and how to catch and redirection moment here: https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.navigated(v=vs.110).aspx
I believe this example will help you:
// Shows ModalWindow upon navigation.
private void webBrowser1_Navigated(object sender,
WebBrowserNavigatedEventArgs e)
{
MessageBox.Show("you are here:" + WebBrowserNavigatedEventArgs.Url);
}

How to open links in wpf webview in default explorer

My webview display a html page which contains lots of links, if I click the link, the new page will open in the webview, is there a way to open the link in default browser rather than in webview?
You can handle the WebView.NavigationStarting event as follows:
private void navigationStartingHandler(object sender, WebViewNavigationStartingEventArgs e)
{
e.Cancel = true;
Process.Start(e.Uri.ToString());
}
Here and here are more answers about opening web pages in default browser

WebBrowser does not change

I'm making an application in C# which, depending of a variable, shows one web page or another.
When I push a button, the program load the userName and the webBrowser should show a different web page. Here is my source code:
private void button1_Click(object sender, EventArgs e) {
string url = "http://www.url.com/" + userName;
webBrowser1.Navigate(url);
webBrowser1.Refresh();
}
The problem is that, when I push the button a second time with a different variable, the web browser reloads the same web page.
I think it's because of the webBrowser1.Refresh(); you don't need it and i think you are pushing the button 2 consecutive times with different values and it gives you the impression that it's loading another page but it isn't. try to remove that line and add an event to the Navigated method of your WebBrowser object in order to obtain a feedback when the browser is done loading the page.
I have solved my problem. I had set the property AllowNavigation to false, so, when I tried to change the web page, it didn't allow me to did it. Anyway, I needed to remove the Refreshcall to make it work.

How do I capture a navigation event in a webview on Windows 8?

I have a Webview in my app and I want to intercept any taps and open the links in IE rather than inside the Webview in the app.
I can only see NavigationFailed and LoadingComplete events, nothing regarding an "about to navigate" event which I could intercept.
It seems there isn't any way to catch any navigation events. However, you can intercept script events called in JavaScript with window.external.notify()
Assuming the page is something you're hosting yourself, you can replace
LINK
With
LINK
Then in your project you'll want to add
webview.ScriptNotify += webview_ScriptNotify;
webview.AllowedScriptNotifyUris = WebView.AnyScriptNotifyUri;
protected async void webview_ScriptNotify(object sender, NotifyEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri(e.Value));
}

C#, Windows Phone 7, Using if-else statement to check which page is displayed

Now I'm developing a Windows Phone 7 app, my app has three buttons located at the applicaton bar. Here is the event handler for these three buttons:
//app bar page navigation
private void ApplicationBarIconButton_Click1(object sender, EventArgs e)
{
if(//check if the current displayed page is mainpage)
{
//do nothing
}
else
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));
}
}
private void ApplicationBarIconButton_Click2(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/Audios.xaml", UriKind.RelativeOrAbsolute));
}
private void ApplicationBarIconButton_Click3(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/Statistics.xaml", UriKind.RelativeOrAbsolute));
}
The button navigation works well except the first one (Button_Click1) because when I first access the main page and click the first button the app will automatically go back to app list.
So I want to use if-else statement to check which page is currently displayed and then decide whether to navigate or stay in the current page.
It looks like you are using the ApplicationBar like you would use a TabBar within iPhone (or similar in Android, Bada, etc too)
In WP7, the Metro style is typpically to use a Pivot or Panorama rather than a "Tab Bar" for this type of navigation.
If you do want to use the ApplicationBar like this:
then you can (the WP7 Marketplace will allow it) but users might feel it's not very Metro.
then you might want to consider disabling the appropriate button rather than just stubbing out the action.
then you can detect the currently shown page using CurrentSource on the NavigationService
Also, please do note that if you try to navigate from MainPage.xaml to the same url MainPage.xaml then you will see an exception - as I recall, the navigation service complains about url fragments not being supported.
Button click1 should be removed from the main page. It makes no sense to have that button there.
Other pages should use the back button to return to the main page. Otherwise you mess up your back stack.

Categories

Resources