/// <summary> /// Initializes several code routines after the webkit containing element loads /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void browserContainer_Loaded(object sender, RoutedEventArgs e) { WindowsFormsHost host = new WindowsFormsHost(); wkBrowser = new WebKit.WebKitBrowser(); host.Child = wkBrowser; this.browserContainer.Children.Add(host); wkBrowser.Navigate(ConfigurationManager.AppSettings["url"]); this.ViewModel.PropertyChanged += (o, f) => { if (f.PropertyName.Equals("URI")) { MakeJSCall(this.ViewModel.URI); playSoundFeedback(); } }; setupTimer.Start(); }
public BrowserHelper(string path, Control browserContainer, object scriptObject,bool isUrl = false) { Browser = new WebKitBrowser(); Browser.Dock = DockStyle.Fill; browserContainer.Controls.Add(Browser); Browser.GetScriptManager.ScriptObject = scriptObject;//必须在Add到父控件后GetScriptManager才不为空 Browser.Navigate(isUrl ? path : LocalToUrl(AppDomain.CurrentDomain.BaseDirectory + path)); }
public BrowserHelper(BrowserHelperParam p) { Browser = new WebKitBrowser(); Browser.Dock = DockStyle.Fill; Browser.Load += (o, e) => { Browser.GetScriptManager.ScriptObject = p.ScriptObject;//必须在Add到父控件后GetScriptManager才不为空 }; p.Container.Controls.Add(Browser); Browser.Navigate(p.GetUrl()); }
void AddTab(string url) { WebKitBrowser browser = new WebKitBrowser(); TabPage tab = new TabPage(); tab.Controls.Add(browser); browser.Name = "WebKitBrowser"; browser.Dock = DockStyle.Fill; tabControl1.Controls.Add(tab); tabControl1.SelectedTab = tab; AddEvents(browser); browser.Navigate(url); }
public WebBrowserPageView(int type, int webBrowserType = 0) { InitializeComponent(); if (type == 1) { serverIndexPage = CompnayIndexPage; lblTitle.Content = "公司介绍"; } else { serverIndexPage = SchoolIndexPage; lblTitle.Content = "校园介绍"; } //默认WebBrowser if (webBrowserType == 0) { webBrowser = new System.Windows.Forms.WebBrowser(); webBrowser.ObjectForScripting = new WebBrowserCallbackClass(); webBrowser.ScriptErrorsSuppressed = true; webBrowser.Navigate(serverIndexPage); windowsFormsHost.Child = webBrowser; grdBrowserHost.Children.Add(windowsFormsHost); } else { kitBrowser = new WebKit.WebKitBrowser(); kitBrowser.Navigate(serverIndexPage); windowsFormsHost.Child = kitBrowser; grdBrowserHost.Children.Add(windowsFormsHost); kitBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(kitBrowser_DocumentCompleted); } if (System.Configuration.ConfigurationManager.AppSettings["IsDev"] == "true") { this.Topmost = false; } }
public MainForm(string url, string tmpname) { InitializeComponent(); browser = new WebKitBrowser(); browser.Visible = true; browser.Dock = DockStyle.Fill; browser.Name = "browser"; browser.IsWebBrowserContextMenuEnabled = false; browser.IsScriptingEnabled = false; Controls.Add(browser); RegisterBrowserEvents(); fsw = new FileSystemWatcher(Path.GetDirectoryName(tmpname)); fsw.Created += new FileSystemEventHandler(fsw_Created); fsw.EnableRaisingEvents = true; temp_file_name = tmpname; browser.Navigate(url); browser.Focus(); }
private void uiDelegate_CreateWebViewWithRequest(IWebURLRequest request, out WebView webView, bool popup = false) { WebKitBrowser b = new WebKitBrowser(); if (request != null) { if (!string.IsNullOrEmpty(request.url())) b.Navigate(request.url()); } webView = (WebView) b.webView; string url = newwindowurl; if (string.IsNullOrEmpty(newwindowurl) && request != null) url = request.url(); NewWindowRequestEventArgs args = new NewWindowRequestEventArgs(url); if (popup == true) { PopupCreated(this, new NewWindowCreatedEventArgs(b)); } else { NewWindowRequest(this, args); NewWindowCreated(this, new NewWindowCreatedEventArgs(b)); } //if (this.Focused == false || ElementAtPoint(this.PointToClient(Cursor.Current.HotSpot)).Type == ElementType.Body || (GetCurrentElement().Type != ElementType.LinkOrUknown || GetCurrentElement().TagName == "BODY" || GetCurrentElement().TagName == "IFRAME" || GetCurrentElement() == null && GetCurrentElement().TagName != "OBJECT")) // { // PopupCreated(this, new NewWindowCreatedEventArgs(b)); // } // else // { // NewWindowRequest(this, args); // NewWindowCreated(this, new NewWindowCreatedEventArgs(b)); // } }
public WebBrowserTabPage(WebKitBrowser browserControl, bool goHome) { InitializeComponent(); statusStrip = new StatusStrip(); statusStrip.Name = "statusStrip"; statusStrip.Visible = true; statusStrip.SizingGrip = false; container = new ToolStripContainer(); container.Name = "container"; container.Visible = true; container.Dock = DockStyle.Fill; statusLabel = new ToolStripLabel(); statusLabel.Name = "statusLabel"; statusLabel.Text = "Done"; statusLabel.Visible = true; iconLabel = new ToolStripLabel(); iconLabel.Name = "iconLabel"; iconLabel.Text = "No Icon"; iconLabel.Visible = true; progressBar = new ToolStripProgressBar(); progressBar.Name = "progressBar"; progressBar.Visible = true; statusStrip.Items.Add(statusLabel); statusStrip.Items.Add(iconLabel); statusStrip.Items.Add(progressBar); container.BottomToolStripPanel.Controls.Add(statusStrip); // create webbrowser control browser = browserControl; browser.Visible = true; browser.Dock = DockStyle.Fill; browser.Name = "browser"; //browser.IsWebBrowserContextMenuEnabled = false; //browser.IsScriptingEnabled = false; container.ContentPanel.Controls.Add(browser); browser.ObjectForScripting = new TestScriptObject(); // context menu this.Controls.Add(container); this.Text = "<New Tab>"; // events browser.DocumentTitleChanged += (s, e) => this.Text = browser.DocumentTitle; browser.Navigating += (s, e) => statusLabel.Text = "Loading..."; browser.Navigated += (s, e) => { statusLabel.Text = "Downloading..."; }; browser.DocumentCompleted += (s, e) => { statusLabel.Text = "Done"; }; browser.ProgressStarted += (s, e) => { progressBar.Visible = true; }; browser.ProgressChanged += (s, e) => { progressBar.Value = e.ProgressPercentage; }; browser.ProgressFinished += (s, e) => { progressBar.Visible = false; }; if (goHome) browser.Navigate("http://www.google.com"); browser.ShowJavaScriptAlertPanel += (s, e) => MessageBox.Show(e.Message, "[JavaScript Alert]"); browser.ShowJavaScriptConfirmPanel += (s, e) => { e.ReturnValue = MessageBox.Show(e.Message, "[JavaScript Confirm]", MessageBoxButtons.YesNo) == DialogResult.Yes; }; browser.ShowJavaScriptPromptPanel += (s, e) => { var frm = new JSPromptForm(e.Message, e.DefaultValue); if (frm.ShowDialog() == DialogResult.OK) e.ReturnValue = frm.Value; }; }
void ImageContextMenu(object sender, EventArgs e) { owner.Navigate(FormatImageLink(owner.GetCurrentElement().GetAttribute("src"))); }
void LinkContextMenu_Click(object sender, EventArgs e) { owner.Navigate(owner.LastSelectedLink); }
void SearchContextMenu_Click(object sender, EventArgs e) { owner.Navigate("http://www.google.com/search?q=" + owner.SelectedText); }
public WebBrowserTabPage(WebKitBrowser browserControl, bool goHome) { InitializeComponent(); statusStrip = new StatusStrip(); statusStrip.Name = "statusStrip"; statusStrip.Visible = true; statusStrip.SizingGrip = false; container = new ToolStripContainer(); container.Name = "container"; container.Visible = true; container.Dock = DockStyle.Fill; statusLabel = new ToolStripLabel(); statusLabel.Name = "statusLabel"; statusLabel.Text = "Done"; statusLabel.Visible = true; iconLabel = new ToolStripLabel(); iconLabel.Name = "iconLabel"; iconLabel.Text = "No Icon"; iconLabel.Visible = true; progressBar = new ToolStripProgressBar(); progressBar.Name = "progressBar"; progressBar.Visible = true; statusStrip.Items.Add(statusLabel); statusStrip.Items.Add(iconLabel); statusStrip.Items.Add(progressBar); container.BottomToolStripPanel.Controls.Add(statusStrip); // create webbrowser control //IWebView wv = (IWebView)browserControl.GetWebView(); browser = browserControl; browser.Visible = true; browser.Dock = DockStyle.Fill; browser.Name = "browser"; browser.IsWebBrowserContextMenuEnabled = false; /* {@@} */ //browser.IsScriptingEnabled = false; container.ContentPanel.Controls.Add(browser); browser.ObjectForScripting = new TestClass(); // context menu this.Controls.Add(container); this.Text = "<New Tab>"; // events browser.DocumentTitleChanged += (s, e) => this.Text = browser.DocumentTitle; browser.Navigating += (s, e) => statusLabel.Text = "Loading..."; browser.Navigated += (s, e) => { statusLabel.Text = "Downloading..."; }; browser.DocumentCompleted += (s, e) => { statusLabel.Text = "Done"; }; browser.ProgressStarted += (s, e) => { progressBar.Visible = true; }; browser.ProgressChanged += (s, e) => { progressBar.Value = e.ProgressPercentage; }; browser.ProgressFinished += (s, e) => { progressBar.Visible = false; }; if (goHome) { string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); string htmlPath = Path.Combine(appPath, "index.html"); browser.Navigate(Uri.EscapeUriString(new Uri(htmlPath).ToString())); } browser.ShowJavaScriptAlertPanel += (s, e) => MessageBox.Show(e.Message, "[JavaScript Alert]"); browser.ShowJavaScriptConfirmPanel += (s, e) => { e.ReturnValue = MessageBox.Show(e.Message, "[JavaScript Confirm]", MessageBoxButtons.YesNo) == DialogResult.Yes; }; browser.ShowJavaScriptPromptPanel += (s, e) => { var frm = new JSPromptForm(e.Message, e.DefaultValue); if (frm.ShowDialog() == DialogResult.OK) e.ReturnValue = frm.Value; }; /* {@@} */ if (!browser.IsWebBrowserContextMenuEnabled) { CreateContextMenu(); // ContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(ContextMenuStrip_Opening); browser.ContextMenuOpen += new EventHandler(ContextMenuStrip_Opening2); } /* {@@} */ }
public WebBrowserTabPage(WebKitBrowser browserControl, bool goHome) { InitializeComponent(); statusStrip = new StatusStrip(); statusStrip.Name = "statusStrip"; statusStrip.Visible = true; statusStrip.SizingGrip = false; container = new ToolStripContainer(); container.Name = "container"; container.Visible = true; container.Dock = DockStyle.Fill; statusLabel = new ToolStripLabel(); statusLabel.Name = "statusLabel"; statusLabel.Text = "Done"; statusLabel.Visible = true; iconLabel = new ToolStripLabel(); iconLabel.Name = "iconLabel"; iconLabel.Text = "No Icon"; iconLabel.Visible = true; statusStrip.Items.Add(statusLabel); statusStrip.Items.Add(iconLabel); container.BottomToolStripPanel.Controls.Add(statusStrip); // create webbrowser control browser = browserControl; browser.Visible = true; browser.Dock = DockStyle.Fill; browser.Name = "browser"; container.ContentPanel.Controls.Add(browser); // context menu this.Controls.Add(container); this.Text = "<New Tab>"; // events browser.DocumentTitleChanged += (s, e) => this.Text = browser.DocumentTitle; browser.Navigating += (s, e) => statusLabel.Text = "Loading..."; browser.Navigated += (s, e) => { statusLabel.Text = "Downloading..."; }; browser.DocumentCompleted += (s, e) => { statusLabel.Text = "Done"; }; if (goHome) browser.Navigate("http://www.google.com"); browser.ApplicationName = "WebKit.NET-test"; }