public void GoBack() { if (UrlReferrer == Request.Url.ToString()) { NameValueCollection kv = UWeb.ParseQs(UrlReferrer); string url = ""; Response.Redirect(url, true); } else { Response.Redirect(UrlReferrer, true); } }
public void ShowPage(string url) { Visibility = Visibility.Visible; Match m = Regex.Match(url, @"^(https?:\/\/)?(www\.)(?<url>.+)$"); if (m.Success) { string sUrl = $@"http://www.{m.Groups["url"].Value}"; UWeb.Navigate(sUrl); } else { UWeb.Navigate(@"https://www.duckduckgo.com/?q=" + url); } }
public WebBrowser() { InitializeComponent(); Height = SystemParameters.PrimaryScreenHeight; Width = SystemParameters.PrimaryScreenWidth; WindowStartupLocation = WindowStartupLocation.CenterScreen; KeyDown += (sender, e) => { if (e.Key == Key.Escape) { UWeb.Dispose(); Close(); } }; UWeb.Navigated += (sender, e) => { //Hack so that the 'load javascript?' prompt does not show up dynamic activeX = UWeb.GetType().InvokeMember("ActiveXInstance", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, UWeb, new object[] { }); activeX.Silent = true; Navigated?.Invoke(e.Uri.ToString()); NavUrl.Text = e.Uri.ToString(); }; NavUrl.KeyDown += (sender, e) => { if (e.Key == Key.Enter) { e.Handled = true; try { ShowPage(NavUrl.Text); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }; Loaded += (sender, e) => { IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(this).Handle; //If you allow transparency on the window, the web browser does not render //By using WinAPI, we can bypass that bug by setting the window properties manually SetWindowLong(hWnd, -16, 0x80000000); }; }
public void Redirect(string url, params object[] pv) { UWeb.Redirect(url, pv); }