I wanted to implement the Facebook Like button into my C# application using the Web Browser control but i encountred a problem with Internet Explorer (After clicking on like button, the facebook login popup appears) but iexplore block and ask me whether to recover the page.
Therfore, i downloaded geckoFx to embed Mozilla on my application instead of the in built Web Browser control ! But now when i click on the Like button on the Gecko browser, i get a blank page. And when i right click the page to view the source i don't see anything (blank page)
Maybe the problem is either the GeckoFX browser doesn't support Popups or doesn't support Javascript
How to implement Facebook Like Button inside GeckoFX browser in C# Windows Forms ?
I'm using XUL runner 1.9.1.19
New Windows and tabs are not handled automatically. You need to create events for those:
private void webBrowser_CreateWindow(object sender, GeckoCreateWindowEventArgs e) {
e.WebBrowser = NewWindow();
}
private void webBrowser_CreateTab(object sender, GeckoCreateTabEventArgs e) {
e.WebBrowser = NewWindow();
}
private GeckoWebBrowser NewWindow() {
BrowserForm frm = new BrowserForm();
frm.Show();
return frm.WebBrowser;
}
Here BrowserForm must contain a public property that points to the GeckoWebBrowser control.
Related
I have a main form that opens a new form that contains a web browser control that navigates to the entered url when it is loaded. I've tried different things I've found and this is my latest code: I have a function (GoToURL) that is triggered at the Shown event of the form which is here:
public delegate void Launch();
private void launchBrowser()
{
webBrowser1.Navigate(GlobalData.URL);
}
private void GoToURL(object sender, EventArgs e)
{
webBrowser1.Invoke(new Launch(launchBrowser));
}
I have nothing in the Document Completed function:
void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
The web browser control loads the url just fine and I can scroll around in it, but on some links or buttons the control goes white and nothing happens. It won't proceed with the desired function. A more specific example is I am logging into a site and once I click the submit button it just hangs there. A "loading" image is presented and it just sits there. I know the Document Completed function above is triggered when this happens, too.
I apologize for my inexperience with C# and this is the first time using the web browser control (forms not wpf), so I am at a loss of what to try. I suspect its a threading issue, but that's as far as I got.
You are experiencing issues within the browser itself. Please launch IE and test the same there. I suspect you'll see the same issues.
Your experience is tied to the version of Internet Explorer you have in your system, and javascript errors have been frequents in the earlier versions of IE. Upgrade to IE11 in any case.
If that's not an option, try using a browser control with a different rendering engine. I'm too lazy to find and list the options, but I've used a few and they work well.
to avoid JavaScript Errors please follow this
public frmMain()
{
//Java Script Error popup block
webBrowser1.ScriptErrorsSuppressed = true;
}
Please Check this on loading Uri using
webBrowser1.Url = new Uri(Url.Trim().ToString());
Url - your desired Url
When navigating using the webview in a Windows Store app any links which try to open in a new tab/windows or opened in internet explorer thus practically pulling users from my app. is there any way to handle the link event to either force the links to open in current view or a way to run code to create a new tab within my own app. i have had a look around and can't seem to see much in the way of a defined way of doing this.
You can hook up to the WebViews "NavigationStarting" event.
The you can cancel the navigation and reissue it from within your code so it navigates inside the webview.
Xaml:
<WebView NavigationStarting="WebView_NavigationStarting" />
Codebehind:
private void WebView_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
{
if (args.Uri != null)
{
args.Cancel = true;
sender.Navigate(args.Uri);
}
}
But you will loose the ability to open links in new windows completely, as you only have the uri itself available in the event handler.
Uri will be null if you use the NavigateToString operations on the webview.
I have added a WebBrowser control on a page. If the user taps on any link in the WebBrowser I need to get the Uri of the request and load it in a new page. Im using WebBrowser class's Navigating event to get the url that is requested. To achieve what I need to do, I need to differentiate whether the navigation happens because of a link is clicked or by calling Navigate method or any redirection has happened. In iOS UIWebViewDelegate's shouldStartLoadWithRequest method passes UINavigation type as one of the arguments. This argument says whether the link is clicked or something else has happened like initial load or some redirection. How to find out this in WP8 WebBrowser control ?.
As mztan said there is no inbuilt way to detect the url click on a WebBrowser control in Windows phone 8.
Set a Navigating event to the WebBrowser and NavigatingEventArgs(argument) gives you the uri which have to be converted to string.Check the below Code.
private void webBrowser1_Navigating(object sender, NavigatingEventArgs e)
{
string val = e.Uri.ToString();
}
I am currently working on an app for WP7 for my university, and need a temporary solution to a problem. Now this solution is, that I will be loading a webpage using the web browser control for WP7. For example: http://m.iastate.edu/laundry/
Now as you see on the webpage, there are certain elements I want to hide, for example the back button. For now, what I have done to handle the back button is something like this:
private void webBrowser1_Navigating(object sender, NavigatingEventArgs e)
{
// Handle loading animations
// Handle what happens when the "back" button is pressed
Uri home = new Uri("http://m.iastate.edu/");
// The the current loading address is home
// Cancel the navigation, and go back to the
// apps home page.
if (e.Uri.Equals(home))
{
e.Cancel = true;
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
}
Now that works beautifully, except for the part that there is a back button on the hardware.
So my second option is to completely hide the back button ONLY on that page, and not its children. So not on http://m.iastate.edu/laundry/l/0
I am still debating on just parsing the data and displaying it in my own style, but I'm not sure if that's completely needed seeing how the data needs constant internet service and is already in a well-put format. Plus, I feel like that would be a waste of resources? Throw in your opinions on that too :)
Thanks!
You should inject a script in the page with InvokeScript.
Here is the kind of Javascript code you need to remove the back button:
// get the first child element of the header
var backButton = document.getElementsByTagName("header")[0].firstChild;
// check if it looks like a back button
if(backButton && backButton.innerText == "Back") {
// it looks like a back button, remove it
document.getElementsByTagName("header")[0].removeChild[backButton];
}
Call this script with InvokeScript:
webBrowser1.InvokeScript("eval", "(function() { "+ script +"}()");
Warning: IsScriptEnabled must be set to true on the web control
If the removal of the back button depends of the page, just test the navigating URI in C# and inject the script if neeeded.
I've created a WPF Desktop Application with C# and placed a System.Windows.Controls.WebBrowser.
Typing this (Where {0} is my app id/key)
https://www.facebook.com/dialog/oauth?&client_id={0}&response_type=token&redirect_uri=https://www.facebook.com/connect/login_success.html&display=popup&scope=publish_stream,offline_access
manually into my firefox/ie/whatever and going to the workflow sends my back to
https://www.facebook.com/connect/login_success.html#access_token=TOKEN
that's great so far.
But navigating my System.Windows.Controls.WebBrowser to the workflow redirects this browser to
https://www.facebook.com/connect/login_success.html
WITHOUT the access token. What am I doing wrong?
I hit something like this while implementing Facebook PowerShell Module. You may be hitting a bug in WPF per http://facebooksdk.codeplex.com/discussions/261528. I had to drop back to WinForms for implementing the login capability only. This also fixed an odd crash-on-exit which I had been experiencing.
I've come up with a workaround. The WPF browser cuts off the hash-part of an url, the WinForms webbrowser doesn't.
So watch this code behind of my XAML window which I'm going to use for getting Facebook app permissions from a user:
public partial class DiagnosticBrowserWindow : Window
{
public DiagnosticBrowserWindow(string urlToRequest)
{
InitializeComponent();
System.Windows.Forms.WebBrowser shadowBrowser = new System.Windows.Forms.WebBrowser();
shadowBrowser.Navigated += (sender, e) =>
{
// the access token is now
// here in e.Url
};
this.Browser.Navigated += (sender, e) =>
{
if (this.Browser.Source.AbsoluteUri.StartsWith("https://www.facebook.com/connect/login_success.html"))
{
shadowBrowser.Navigate(urlToRequest);
}
};
this.Browser.Navigate(urlToRequest);
}
}
This is working, because as soon the app permissions have been granted (which we detect by detecting a redirect to login_success.html) we send the shadow browser (which is a WinForms Webbrowser) to the inital request page which is:
https://www.facebook.com/dialog/oauth?&client_id={0}&response_type=token&redirect_uri=https://www.facebook.com/connect/login_success.html&display=popup&scope=publish_stream,offline_access
Facebook will detect, that the permissions already have been granted and send the shadowBrowser back to login_success.html and this time you can read the hash-part.