there is a webview in my UWP app. By default the webview does not show the currently loaded contents url. Is it somehow possible to display the url as in the browser search field for instance?
For example if google is loaded in the webview i want to see the url "https://www.google.de/?gws_rd=ssl" somewhere.
Best wishes
You could show the url in a textbox in the NavigationStarting event
void webView1_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
{
string url = "";
try { url = args.Uri.ToString(); }
finally
{
address.Text = url;
appendLog(String.Format("Starting navigation to: \"{0}\".\n", url));
pageIsLoading = true;
}
}
https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview.navigationstarting.aspx
Related
I am using
HtmlElement elem = webBrowser1.Document.GetElementFromPoint(e.ClientMousePosition);
to get element from point in web browser control. I want to get the html element on mouse click in web view.Any alternative to this in web view control
As per the explanation here:
Web view
Interacting with web view content
You can interact with the content of the web view by using the
InvokeScriptAsync method to invoke or inject script into the web view
content, and the ScriptNotify event to get information back from the
web view content.
So you could do something like this:
private void WebView1_DOMContentLoaded(object sender, Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.WebViewControlDOMContentLoadedEventArgs e)
{
String func = #" document.addEventListener('click', function(e){
//Get the Div Tag Name and its ID as string back into our code
window.external.notify(e.target.tagName + '(' + e.target.id + ')');
});";
webView1.InvokeScriptAsync("eval", func);
}
private void WebView1_ScriptNotify(object sender, Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.WebViewControlScriptNotifyEventArgs e)
{
string s = e.Value; //This will give you the Div Tag Name and ID
}
I want to place a link inside the description field of my applications about box which will direct users to a wiki page for more help. I can't figure out how to make the address appear as a link.
I set the description through the assembly information properties.
There's a WinForms control you can use to achieve what you want: the LinkLabel.
Simply add one to your AboutBox layout and double click it. A handler to its LinkClicked event will be created, and there you can then use Process.Start to open your website's URL.
public AboutBox1()
{
InitializeComponent();
this.Text = String.Format("About {0}", AssemblyTitle);
this.labelProductName.Text = AssemblyProduct;
this.labelVersion.Text = String.Format("Version {0}", AssemblyVersion);
this.labelCopyright.Text = AssemblyCopyright;
this.labelCompanyName.Text = AssemblyCompany;
this.textBoxDescription.Text = AssemblyDescription;
this.Link.Text = "Visit our website!";
this.Link.Tag = WpfApplication2.Properties.Resources.website;
}
private void Link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start((sender as LinkLabel).Tag.ToString());
}
In my case, I've saved the URL as an application resource. And I've showed it separately from the Assembly Description.
If you want the link to appear inside the Assembly Description, it's quite a bit more complicated...
I need to get a cookie from webview control (W 8.1, c#, xaml).
First I load the page inside the Webview like this:
<WebView x:Name="WebviewControl" FrameNavigationCompleted="Webview_FrameNavigationCompleted" />
WebviewControl.Navigate(new Uri("example.com"));
Then, the user log inside tha page and I need to get the cookie.
I try this:
private void Webview_FrameNavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
HttpBaseProtocolFilter baseFilter = new HttpBaseProtocolFilter();
foreach (HttpCookie cookie in baseFilter.CookieManager.GetCookies(new Uri(sender.Source.ToString()))
{
if (cookie.Name.Equals("cookieName"))
{
string value = cookie.Value;
}
}
}
The problem is that the cookie dosen`t exist inside the cookiemanager.
I doing something wrong?
I am in the process of making a multi tab browser and have run into some problems. I would like it so when the user has added a new tab using a button, that every site they then choose to navigate to will update to the tab url. So if the user changes tab or opens a new one, it the last website will be saved if they return to the previous tab.
Here is the code while creating a new tab & When a tab is selected from the created ones
private void addNewTab(string url)
{
TabEntry urlObj = new TabEntry();
urlObj.URL = url;
urlObj.timestamp = DateTime.Now.ToString("HH:mm");
if (url.Contains("/"))
{
urlObj.Name = url.Remove(url.IndexOf('/'));
}
else
{
urlObj.Name = url.Remove(url.IndexOf('.'));
}
tabs.Insert(0, urlObj);
listBoxTabPage.ItemsSource = null;
listBoxTabPage.ItemsSource = tabs;
Browser.Navigate(new Uri("http://www.google.com", UriKind.Absolute));
//selectedTab = listBoxTabPage.SelectedValue as TabEntry;
}
private void ListBoxTabPage_SelectionChanged(object sender, GestureEventArgs e)
{
selectedTab = listBoxTabPage.SelectedValue as TabEntry;
Browser.Navigate(new Uri("http://www." + selectedTab.URL, UriKind.Absolute));
PivotItems.SelectedItem = BrowserPage;
}
Here is the code where it should update the selected tabs url, in the Browser_Navigated methord
void Browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
_deactivatedURL = e.Uri;
_progressIndicator.IsVisible = false;
string url = Convert.ToString(e.Uri);
//selectedTab.URL = url;
addHistoryRecord(url);
}
Where it is commented out I think is the problem. I believe the code does not know which one is the selectedTab. To fix this error should I create a methord which updates the url of the tab, each time the browser navigates. And how would the program know which tab is currently in use.
If you need any more details please comment and I will be happy to explain in further detail.
You just set listBoxTabPage.ItemsSource = null before you set tabs as ItemsSource. It may clears your listBoxTabPage.SelectedValue.
I think you can just set listBoxTabPage.SelectedValue = urlObj in addNewTab().
Then you begin navigate to a new uri in ListBoxTabPage_SelectionChanged, but it seems to be wrong that you just append a prefix string http://www. to an full url. It may triggers NavigateFailed event if you navigate to a non-exist website.
Browser.Navigate(new Uri("http://www." + selectedTab.URL, UriKind.Absolute));
What's more, ListBoxTabPage_SelectionChanged may triggers twice because the old value is cleared and the new value is set.
I have one image button in the custom control like below.
public string SearchTableName = string.Empty;
public string SearchColumnName = string.Empty;
public string SiteURL = string.Empty;
ImageButton _imgbtn;
protected override void OnInit(EventArgs e)
{
_imgbtn = new ImageButton();
_imgbtn.ImageUrl = ImageURL;
_imgbtn.OnClientClick = "ShowSearchBox('" + SiteURL +"/_layouts/CustomSearch/SearchPage/Searchpage.aspx?table_name=" + SearchTableName + " &column_name=" + SearchColumnName + "')";
}
On Clicking of the image button I want to migrate to the another window which is a popup. For this I written a javascript function. I am setting the SearchTableName and SearchColumnName in the web page in which we are consuming this custom control like below. Before consuming I registered this control in web page with register tag.
<ncc:SearchControl runat="server" ID="txtSearchControl" /> In code behind file of this webpage I am using following code to set the values.
protected void Page_Load(object sender, EventArgs e)
{
txtSearchControl.ImageURL = "_layouts/Images/settingsicon.gif";
txtSearchControl.SearchTableName = "Employees";
txtSearchControl.SearchColumnName = "LastName";
txtSearchControl.SiteURL = "http://Sp2010:8787";
}
Now coming to the problem, when I click the image button the SearchTableName and SearchColumnName values are not coming. I think I am calling OnClientClick function, thats why the values are not being set. But how to set the values for the custom control based on the values setting in the webpage. If I use the Click function will it serve my purpose? If so, how to call that javascript function from this click event.
Finally got solution. I am initializing the values in the page init method in the custom control. Thats why the values i am setting in the visual webpart page are not being captured. Now I changed the initializing the values in CreateChildControl method. Now it works perfectly. Thank you.