Windows Universal App Open webbrowser with link - windows

I am making an universal app and when i click a certain button, i need to open the webbrowser with a link. I got the link as a string in a variable but the windows 7 / 8 app ways such as "Proces" and Webbrowser objects give errors.

In windows apps, you can't simply open other apps/programms.
The only posibility is to use the Launcher:
Windows.System.Launcher.LaunchUriAsync(new Uri("http://www.google.de"));
The Launcher looks up the default program/app which is assosiated to the uri-scheme (in this case "http://" for webbrowsers) and forwards this call

others then above you can go Package.app manifest change the start page to the URL that you want or another method by using web control set the source to the URL you needed.

use scope async, it will open link to the mobile,PC default default browser for UWP
private async void Button_Click(object sender, RoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("http://www.fmradiotune.blogspot.com"));
}

Related

Xamarin Forms WebView open external link

I have a webview inside my application and when an external link is clicked (that in normal browser is open in a new tab), I can't then go back to my website.
It is possible when a new tab is open to have the menu closed that tab like Gmail do ?
The objective is that, whenever a link is clicked, the user would have the choice to choose which option to view the content with, e.g. Clicking a link would suggest open youtube app or google chrome. The purpose is to appear the google chrome option
Or what suggestions do you have to handle this situation ?
If I understood you correctly, you want to have the option to select how to open the web link - inside your app, or within another app's (browser) context.
If this is correct, then you can use Xamarin.Essentials: Browser functionality.
public async Task OpenBrowser(Uri uri)
{
await Browser.OpenAsync(uri, BrowserLaunchMode.SystemPreferred);
}
Here the important property is the BrowserLaunchMode flag, which you can learn more about here
Basically, you have 2 options - External & SystemPreferred.
The first one is clear, I think - it will open the link in an external browser.
The second options takes advantage of Android's Chrome Custom Tabs & for iOS - SFSafariViewController
P.S. You can also customise the PreferredToolbarColor, TitleMode, etc.
Edit: Based from your feedback in the comments, you want to control how to open href links from your website.
If I understood correctly, you want the first time that you open your site, to not have the nav bar at the top, and after that to have it. Unfortunately, this is not possible.
You can have the opposite behaviour achieved - the first time that you open a website, to have the nav bar and if the user clicks on any link, to open it externally (inside a browser). You have 2 options for this:
To do it from your website - change the a tag's target to be _blank like this;
To do it from your mobile app - create a Custom renderer for the WebView. In the Android project's renderer implementation, change the Control's WebViewClient like so:
public class CustomWebViewClient : WebViewClient
{
public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, IWebResourceRequest request)
{
Intent intent = new Intent(Intent.ActionView, request.Url);
CrossCurrentActivity.Current.StartActivity(intent);
return true;
}
}

How can I add a link to my Xamarin.Forms application so it opens a web page?

I know how to code the buttons, how to use Command but what I would like some advice on is if there's a way to open a web page from the C# code in my application? Is this something I need to do async and is there some function I can call that will do this that works in forms back-end code?
This is would open a web page in your default browser
Device.OpenUri(new Uri("http://something.com"))
I don't think it should be async function in any way
If you want to write in as async download Xamarin.Essentials plugin and write it as
public async Task<bool> OpenBrowser(Uri uri)
{
return await Browser.OpenAsync(uri, BrowserLaunchMode.SystemPreferred);
}
This method returns after the browser was launched and not necessarily closed by the user. The bool result indicates whether the launching was successful or not.
Read on learn.microsoft.com for more information.

How can i use NavigationServices in Application_Activated windows phone 7?

im developin an app for wp7 that it holds pictures and notes with password login. But when app running if user press windows button app is running at background and if user press back button it resumes without asking password again.
i tried to Navigate when app activated but i couldnt manage it in Application_Activated method. is there a way to do that? Or could you advice me sth else that solve my problem.
ty.
here is my code im using to navigate,
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
I got around this issue by using UserControls on the MainPage, showing one if the user had not yet logged in and the other if they had, I set these controls up to show/hide based on certains states in the MainPage and then bind that to the MainViewModel:
private void Application_Activated(object sender, ActivatedEventArgs e)
{
// Ensure that application state is restored appropriately
....your code here to load stuff...
App.ViewModel.MainPageState = "ShowThemTheLogin";
}
}

Scrolling WebBrowser control on Windows phone 7

I want to scroll down or up in the webbrowser control on the windows phone 7 using code behind (no javascript). i mean like using some button to scroll down for example. is that possible?
EDIT:
I tried to call a javascript function using InvokeScript, but it keeps giving me an unknown error 80020006. i tried to do this:
public MainPage()
{
InitializeComponent();
webBrowser1.Navigate(new Uri("http://www.msn.com"));
}
private void button1_Click(object sender, RoutedEventArgs e)
{
webBrowser1.InvokeScript("window.scrollBy(100,100);");
}
something wrong in my code?
There is no way to interact with the scrolling of the page inside a WebBrowser control from outside of it.
In terms of doing it with JavaScript look at windows.scrollBy()
update
Try webBrowser1.InvokeScript("eval", "window.scrollBy(100,100);");
But be aware that the page you're viewing may have overridden eval which coudl prevent this from running.
Note that the WebBrowser control was not intended to be used to view websites directly.
Also, have you tried calling scrollBy directly from within your own page?

Windows Phone 7 navigation to internet from an application

I have the following question:
I have my Windows Phone 7 appplication and I have a HyperlinkButton with the NavigateUri binded to an Uri created like this:
Uri uri = new Uri("http://google/ro",UriKind.Ablosute)
but when I press the button I get the following error :
Navigation is only supported to relative URIs that are fragments, or begin with '/', or which contain ';component/'.\r\nParameter name: uri
What did I do wrong? Or is the WP7 that does not allow to surf the internet from an application with a HyperlinkButton? Since when I create the uri like Uri uri = new Uri("/Page.xaml",UriKind.Relative) it redirects me to Page.xaml in the project.
I found a rather strange workaround that fixes this. Just add a TargetName="_blank" property to your HyperlinkButton control, and it magically starts working.
<HyperlinkButton Content="Google" NavigateUri="http://google.com" TargetName="_blank" />
Chris
You can't use the phone navigation system to navigate to the web (where would you expect it to display?). But you can use the web browser control to display web pages in your app. See this example
You could also use a Web Browser Task something along the lines of
WebBrowserTask wtb = new WebBrowserTask();
wtb.Uri = new Uri("http://www.google.com", UriKind.Absolute);
wtb.Show();
The URL is obsolete. Use Uri, as below.
private void Button_Click(object sender, RoutedEventArgs e)
{
WebBrowserTask wtb = new WebBrowserTask();
wtb.Uri = new Uri("http://www.google.com", UriKind.Absolute);
wtb.Show();
}

Resources