WP8 Webbrowser, stop navigation without killing page - silverlight

I have an app that uses a web browser control to navigate a website. When the user clicks on a hyperlink that will take them out of the site I want to be able to stop the navigation. I tried.
void wgBrowser_Navigating(object sender, NavigatingEventArgs e)
{
if (!e.Uri.AbsoluteUri.Contains(BASEURL))
{
e.cancel = true;
return;
}
progressPB.Visibility = Visibility.Visible;
}
This does in fact stop the navigation, but it kills the page causing a navigation error message to appear in the webbrowser.
I have tried a few things including a wgBrowser.Goback() after navigation, but that is not a real "back", and causes the page to reload complete losing data the user previously entered.
Any help will be greatly appreciated.
Thanks you.

Are u tried IsolatedStorageSettings? Because using IsolatedStorageSettings store the data will be better when the page is navigate.
Example:
private void tbUserName_SelectionChanged(object sender, RoutedEventArgs e)
{
if (appSetting2.Contains("MainPage2"))
{
appSetting2["MainPage2"] = this.tbUserName.Text;
}
else
{
appSetting2.Add("MainPage2", this.tbUserName.Text);
}
}

Use can use the InvokeScreipt method over WebBrowser control to stop page navigation.
yourWebBrowser.InvokeScript("eval", "document.execCommand('Stop');");

Related

Webview2 website connect to audio has to be manually clicked

I am using wpf webview2 to build an app , the webview2 will navigate to my website which has one button to connect to audio , but i want to make it connect to audio automatically , so i tried use code like
document.getElementById("audioBtn").click(); to try to connect to audio.
But seems this doesn't work, i still have to manually click the button rather than trigger the click by script. (maybe due to some browser security policy ?)
I also tried to auto allow the permission in webview2
private void CoreWebView2_PermissionRequested(object sender, CoreWebView2PermissionRequestedEventArgs e) { e.State = CoreWebView2PermissionState.Allow; }
So how can i automatically connect to audio ? Both the WPF application and the web application is mine.. so there is no security risk..
thank you so much...
I also tried to auto allow the permission in webview2
private void CoreWebView2_PermissionRequested(object sender, CoreWebView2PermissionRequestedEventArgs e) { e.State = CoreWebView2PermissionState.Allow; }
You might be trying that click before the content is properly loaded, in which case there will be no document there or element in it.
Assuming this is the problem then you can handle the navigation completed event.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.navigationcompleted?view=webview2-dotnet-1.0.1245.22
Something like:
wv2.CoreWebView2.NavigationCompleted += (s, at) =>
{
wv2.ExecuteScriptAsync("document.getElementById('audioBtn').click();");
};
Before you navigate

Cefsharp - display page loading indication

I'm implemeting a win form which contains a cefsharp chromium-embedded browser.
I'm facing the following problem - sometimes it takes time until a page is loaded.
The problem is that user has no idea that something happens until the page is actually loaded.
I have no control on the pages that the browser displays.
I need to display some kind of loading indication. I searched the web and the only thing that I found was to show an animated loading image while the loading takes place and hide it when the page is loaded (using the load state changed event).
It seems to make things even slower.
Is there anything in Cefsharp infrastructure that I can use? or any other idea of solving it?
Thanks!
ChromeView = new CefSharp.Wpf.ChromiumWebBrowser();
//Adding event listener
ChromeView.NavStateChanged += ChromeView_NavStateChanged;
//Event listener
private void ChromeView_NavStateChanged(object sender, CefSharp.NavStateChangedEventArgs e)
{
if(!e.IsLoading)
{
this.Dispatcher.Invoke(()=> { //Invoke UI Thread
controller.setLoaderinBack(); //UI Update
});
}
else
{
this.Dispatcher.Invoke(() => { //Invoke UI Thread
controller.setLoaderinFront(); //UI Update
});
}
}
For Higher Versions of CefSharp (mine version 81):
ChromeView = new CefSharp.Wpf.ChromiumWebBrowser();
//Adding event listener
ChromeView.LoadingStateChanged += ChromeView_NavStateChanged;
//Event listener
private void ChromeView_NavStateChanged(object sender, LoadingStateChangedEventArgs e)
{
if(!e.IsLoading)
{
//Stuff...
}
else
{
//Stuff...
}
}

Awesomium web browser doesn't show the page

I have made a form which takes a few URLs in the constructor and loads them into some awesomuim web controls on the form.
It worked fine in the first computer but when I move the program to another computer (with the code), it doesn't show the page in the control. when I move the mouse over the control, it shows the busy icon.
But, if i put a breakpoint somewhere in the constructor and then click continue in visual studio, it works fine! I tried to put a sleep in the constructor but it didn't do the job.
here's the code :
public BrowsersWindow(List<string> links)
{
InitializeComponent();
// Thread.Sleep(5000);
Links = links;
Browsers = groupBox1.Controls;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (index < Links.Count && index < Browsers.Count)
{
Awesomium.Windows.Forms.WebControl current =
(Awesomium.Windows.Forms.WebControl)Browsers[index];
try
{
current.Source = new Uri(Links[index]);
}
catch { }
index++;
}
}

Remove 2 Entries from Navigation Journal

In my windows phone 8 app i have to check if user is already login or not before navigating to different pages. If user is not logged in i navigate the user to Login.xaml from where user chooses either login from Facebook or twitter or cancel.
Now when user successfully logs in i navigate the user to appropriate page. My question is how to remove those potential 2 pages (login.xaml and facebook/twitter login)?
NavigationService.BackStack is IEnumerable :(
does anyone has a work around?
If it is the same as using the WPF NavigationService then you can use RemoveBackEntry after you have navigated to the new page.
Update:
If you are using code such as
if (!user.IsLoggedIn)
{
NavigationService.Navigate(new Login());
}
Then you can remove the back entries before anyone has a chance to see them
if (!user.IsLoggedIn)
{
NavigationService.Navigate(new Login());
//Hide back entry
NavigationService.RemoveBackEntry();
}
However if you are unable to do this, for example when you end up with a Facebook/twitter url in the back entry, then instead subscribe to the Navigated event and then remove them
public Login()
{
NavigationService.Navigated += HideEntriesOnNavigated;
}
void HideEntriesOnNavigated(object sender, NavigationEventArgs e)
{
if (IsFacebookLogin(e.Url)
|| IsTwitterLogin(e.Url)
|| IsAppLoginPage(e.Url))
{
NavigationService.RemoveBackEntry();
}
}

Silverlight 3: No change but now I am getting "Page Not Found"

Had a page that was working fine. Only change I made was to add a datagrid to the page (which also added the xmlns) and all of the sudden I'm getting Page Not Found. Checked the UriMappings. Tried the default nav link. No joy.
Ideas?
UPDATE: The answer was that I had a mock class that was not initializing a collection. See Byrant's answer for a way to save yourself some time.
To see what the issue is you need to make one change to your MainPage.xaml.cs:
// If an error occurs during navigation, show an error window
private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
Exception ex = e.Exception;
while (ex.InnerException != null)
{
ex = ex.InnerException;
}
e.Handled = true;
ChildWindow errorWin = new ErrorWindow(ex);
errorWin.Show();
}
Once you've made that change when you start the application you should see the exception instead of the page where the exception occurred.
Firebug is always a good friend to see which kind of requests are called ...
Often the devServer is not closed properly , have a look at the taskbar

Resources