I have written a sidebar gadget which displays a series of links using silverlight. I can host the silverlight in a web site and when I click on the links they open in a new tab. When I package it up as a gadget however the links appear in the gadget, and they can be clicked on, but they do not open a browser window to display the link.
What do I need to do to get this to work?
It's best to launch external links from gadgets using your preferred shell execute method; doing so will launch them in the default browser. When developing gadgets, all my links have an onclick handler which points to the following method:
function launchLink() {
if (this.href.slice(0,7) == "http://") {
System.Shell.execute(this.href);
return false;
}
}
Theoretically, you could modify this slightly and invoke it from your Silverlight code using the HTML bridge.
JS code
function launchLink(href) {
System.Shell.execute(href);
}
Silverlight
// HtmlPage requires using System.Windows.Browser
HtmlPage.Window.Invoke("launchLink", "http://some.com/");
Related
Right now we use the old WPF WebBrowser control to show a web site in our program. Since this old control is based on Internet Explorer 11 and a lot of newer web sites show a message, that they are not running on Internet Explorer 11, we are looking for a replacement for this old control.
We took a look into WebView2 but unfortunately this browser doesn't show up in our setup (WPF control hosted in an ElementHost in WinForms, hosted in an ocx in COM, used in MS Access).
So we take a look in CefSharp now. I didn't get to trying if this browser shows up in our setup because I don't find a solution for a simple requirement in my test program.
I'd like to restrict the user to follow links that might be part of the web site. In WebView2 there's a NavigationStarting event which can be canceled, but I didn't find anything like that in CefSharp.
There's an AddressChanged event, but this also fires when the web site is re-directing.
So, is it somehow possible with CefSharp to load an initial website (including any re-directions) and then doing nothing when a link inside the web site is clicked?
You can cancel navigation in OnBeforeBrowse
public class CustomRequestHandler : CefSharp.Handler.RequestHandler
{
protected override bool OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect)
{
if (request.TransitionType == TransitionType.LinkClicked)
{
//Cancel the request by returning true
return true;
}
return base.OnBeforeBrowse(chromiumWebBrowser, browser, frame, request, userGesture, isRedirect);
}
}
browser.RequestHandler = new CustomRequestHandler();
I am developing a windows phone application.
In a page I placed a button and on this button click I open the webbrowser and redirects to our website pages for some processes. There are many webpages. In the last webpage we added a button "Close". In the close button click I want to close the webbrowser and open the application back with the last state before opening the webbrowser. How can I do this ?
Thanks.
I will refer to the button in the app as "app button" and the button in the web page as "close button".
Add a WebBrowser control called webBrowser1 to the Windows Phone app. Make it cover the entire screen, and set it's Visibility property to Collapsed.
On the app button's click event, use
webBrowser1.Visibility = System.Windows.Visibility.Visible;
webBrowser1.Navigate(new Uri("http://yourwebsite.com/page");
to show the web browser and navigate it to the first page on your website.
Make the close button on the last page of your site navigate to a new page on your site, called "close.html" or whatever you want. In javascript, this would look like
<Button onclick="window.location.href='http://yourwebsite.com/close.html';">
Back in the app: On webBrowser1's Navigating event use,
if (e.Uri.ToString().Contains("close.html"))
{
webBrowser1.Visibility = System.Windows.Visibility.Collapsed;
}
When the you click the button on the last page of your site, it navigates to "close.html". When this happens, the Web Browser's Navigating event fires. Since this event fires every time you change pages, you need to check to see if the new url contains "close.html", the page your close button is navigating to. If it does, the Web Browser will be hidden and you will see your app again.
.
(In VB, the code would be )
webBrowser1.Visibility = System.Windows.Visibility.Visible
webBrowser1.Navigate(New Uri("http://yourwebsite.com/page")
And
If e.Uri.ToString.Contains("close.html")
webBrowser1.Visibility = System.Windows.Visibility.Collapsed
End If
Edit: I was thinking in generic terms when i wrote the answer and did not remember that you are asking specifically about the webbrowser (hence, using a webbrowsertask launcher). Thank you #Claus for point out the OAuth situation. So, i am amending my answer to explain that it is possible and also mention an issue with using the launcher as there is no way guarantee to return back to a given point in your launcher app (as it is with choosers due to the availability of callbacks).
It is not possible to achieve this in general terms. That is, there is an application A which opens another application B and from application B you would like to close-it-and-open-A. There are many reasons why i think it is not possible:
- How does one get the address/reference to the application A. No API for that at the moment.
- There is no content-handler/plugin where a 3rd party can register an app with the web-browser.
- Most importantly, security, security, security. This would open doors for attacks from the web.
However, for your requirement of application B being a web-browser, it is possible to use a task launcher WebBrowserTask. As #claus suggests, you could have Window.close() javascript in your last page to close the browser and hence reveal the app underneath it (hopefully, A). The problem here is that if, the user opens an app (let's call it C) after the browser has launched (and before the browser is closed), and the user does not close C, then when the browser gets closed, the user will be returned to C and not to the launcher App! This is not what you want based on your requirement.
So, if you would like to achieve the kind of effect you are describing in your question, it is best that you embed the Web-browser in your application (as a full-screen app) and from that vantage point you can interact between the web-browser (control) and the (host) app via Javascript.
Hopefully, this helps.
I am trying to implement a simple Facebook login flow using WPF. It turns out that I need to use some sort of embedded browser within the application if the application is a desktop application. Therefore I am using WebBrowser control, but I can't seem to correctly detect the redirecting URL.
Once I load the web page for facebook login, and after login, the browser redirects to a page of the form
https://www.facebook.com/connect/login_success.html#access_token=....
But if I look at the URI source, it only shows up to login_success.html and is cutting off whatever is after the # sign. I need this information for further processing, so I was wondering if anyone could advise on retrieving that access token using WebBrowser (or any other way) in WPF. Thanks!
I was having the saving problem with the WPF Sample in the SDK today. I figured it was a problem with the WPF Webbrowser control (like you had infered). So I used the windows.forms.webbrowser instead of the WPF webcontrol. It is a simple fix.
System.Windows.Forms.Integration.WindowsFormsHost host =
new System.Windows.Forms.Integration.WindowsFormsHost();
_webBrowser = new System.Windows.Forms.WebBrowser();
host.Child = _webBrowser;
this.grid1.Children.Add(host);
_webBrowser.Navigated += new WebBrowserNavigatedEventHandler(webBrowser_Navigated);
_webBrowser.Navigate(_navigateUrl.AbsoluteUri);
This is probably futile, but I'm wondering if anyone out there has experience doing this.
I'm trying to access a Silverlight application hosted within Google Chrome by using System.Windows.Automation (e.g., AutomationElement).
The problem I'm having is that Chrome hosts the Silverlight app within a child process. If I attempt to find the "Silverlight Control" AutomationElement (by using the main process' hWnd), it fails.
If I locate the Silverlight host child process, it does not have a window handle, and if I attempt to find the control using the child process' Handle it fails.
I know it's there... I can see it using Inspect
but I can only find this by clicking in the Silverlight app and navigating up in Inspect. I cannot navigate down from the tab window using AutomationElement.FindFirst or Inspect.
Its like there is a disconnect between the window and the Silverlight plugin that isn't seen in IE or Firefox, and I don't know how to get around it.
Has anybody else been able to do this?
I'm not sure if this helps or not in your instance but I've run into a couple instances where I needed to enable communication into Silverlight from outside (Office Application AddIns that need to communicate with the Silverlight Application). I've used javascript in the html page hosting the Silverlight Application as a bridge for that communication:
function sendToNav(message) {
var nav = document.getElementById("Nav");
nav.content.NavigationPage.HandleScriptedMessage(message);
}
function passMessageToHost(message) {
if (window.external == null) return;
window.external.HandleScriptedMessage(message);
}
If there any additional information I can provide please let me know. Hope this is of some use to you.
I have a windows forms application and which provides a way to search the database based on the provided value. Sometime I need to open the application through a simple html hyperlink with the search result while loading itself. There are two questions/doubts from here.
How to access the existing running windows forms application as url? If this is possible, how can I pass the argument?
If the application is not running, we have to start the application and search the value. This also has to be happened when I click the link.
Simply we can say like, if you open a website link from your outlook email, the link will be opening in existing opened default browser or it will start the new browser(if the browser is not already opened.) I want to achieve the same behavior.
Seems to be the below post is somewhat related to my queries, but this does not solve my problem.
Activate existing browser window with given URL from C# application (without triggering reload)
You can't do this. The default browser launches when you click on a link because it is set up in the registry as the default handler for hyperlinks.