want to open Link in external browser of WP7
Solution 1
You can use the WebBrowserTask
to launch the browser.
I've found that you need to escape the URL you pass to it though :(
Solution 2
Normally, you would do so using Target
property on <a>
tag. But, in WP7
(at least in Emulator), this does not work.
What you could do is intercept using Navigating
event something like following:
void WebBrowser1_Navigating(object sender, NavigatingEventArgs e)
{
if (IsSupposedToOpenInPhoneBrowser(e.Uri))
{
e.Cancel = true;
WebBrowserTask task = new WebBrowserTask();
task.URL = e.Uri.ToString();
task.Show();
}
}
Solution 3
You can use something like that
private void Button_Click_1(object sender, RoutedEventArgs e)
{
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri("http://www.someUrl.com");
webBrowserTask.Show();
}
Shaireen
Functional tester. Former Android Application Developer.
Updated on July 27, 2022Comments
-
Shaireen almost 2 years
The architecture is like:
On click of a button an HTML page opens which contains a link in it. On clicking the links I want to open it in external (default) browser of WP7 such that the application closes and link opens externally. How can I implement this?
Added this control in xaml file:<phone:WebBrowser Name="browser" Margin="0,78,0,0" />
On button click:
private void Information_Loaded(Object sender,RoutedEventArgs e) { Assembly assembly = Assembly.GetExecutingAssembly(); using (Stream stream = assembly.GetManifestResourceStream("index_en.html")) { using (StreamReader reader = new StreamReader(stream)) { string html = reader.ReadToEnd(); browser.NavigateToString(html); } }
Now index_en.html has a link which is to be opened in external browser.
-
Shaireen over 13 yearsHow can i implement it by skipping?
-
Jon Skeet over 13 years@Shaireen: Implement what by skipping? Skipping what?
-
Shaireen over 13 yearssorry for not making myself clear.Actually while using Web browser task i need to pass a url to it.So this url should be the name of html file? or is it the link that shud open?
-
Jon Skeet over 13 years@Shaireen: It's the address to open. The bit you'd put in the address bar in a browser.
-
Shaireen over 13 yearsActually i have an Html file which opens on a button click.This file has the address to be opened in external browser.Now i want to capture click on that link ,only then i can open it externally?how to do that?
-
Jon Skeet over 13 years@Shaireen: So how are you displaying the file? If it's in a WebBrowser control, you should hook into the Navigating event - that will tell you the URL to load. You can then cancel navigation for the control and launch the browser task instead.
-
Jon Skeet over 13 years@Shaireen: No, I don't have VS handy to validate it... but I've given you enough suggestions already... and your question still isn't clear. Are you expecting the user to click on the link, or do you just want it opened immediately? If it's the latter, you'll need to find the link URL from the HTML yourself.
-
Shaireen over 13 yearsExpecting a user click on th link to open it
-
Jon Skeet over 13 years@Shaireen: In that case see an earlier comment - handle the Navigating event from the browser control.
-
Shaireen over 13 years"IsSupposedToOpenInPhoneBrowser(e.Uri)" property is not found.what does it signify?
-
decyclone over 13 yearsIt is just a fake method placeholder if you want to verify/filter Uris before opening them in phone browser... you can do without it.
-
Gaurav Sharma over 10 yearsLink have been moved msdn.microsoft.com/en-us/library/windowsphone/develop/…