Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从webview UWP获取favicon_C#_Uwp_Favicon - Fatal编程技术网

C# 从webview UWP获取favicon

C# 从webview UWP获取favicon,c#,uwp,favicon,C#,Uwp,Favicon,我有一个问题:如何在C#UWP中的网络视图中显示页面的favicon? 我想存储图标以便以后访问它。有办法吗 多谢各位 从webview UWP获取favicon html中有用于描述favicon的快捷方式图标rel属性。您可以使用WebViewInvokeScriptAsync将检测到的方法注入eval函数,并使用window.external.notify将favicon的href传回 例如 public MainPage() { this.InitializeComponent(

我有一个问题:如何在C#UWP中的网络视图中显示页面的favicon? 我想存储图标以便以后访问它。有办法吗

多谢各位

从webview UWP获取favicon

html中有用于描述favicon的
快捷方式图标
rel属性。您可以使用WebView
InvokeScriptAsync
将检测到的方法注入eval函数,并使用
window.external.notify
将favicon的href传回

例如

public MainPage()
{
    this.InitializeComponent();

    MyWebView.LoadCompleted += MyWebView_LoadCompleted;
}

private async void MyWebView_LoadCompleted(object sender, NavigationEventArgs e)
{
     string functionString = @"var nodeList = document.getElementsByTagName ('link');
for (var i = 0; i < nodeList.length; i++)
{
    if ((nodeList[i].getAttribute('rel') == 'icon') || (nodeList[i].getAttribute('rel') == 'shortcut icon'))
    {
        favicon = nodeList[i].getAttribute('href');
        window.external.notify(favicon); 
    }
}";

 await MyWebView.InvokeScriptAsync("eval", new string[] { functionString });

}

private void MyWebView_ScriptNotify(object sender, NotifyEventArgs e)
{
   var url = e.Value;
}
public主页()
{
this.InitializeComponent();
MyWebView.LoadCompleted+=MyWebView\u LoadCompleted;
}
私有异步void MyWebView_加载已完成(对象发送方,NavigationEventArgs e)
{
string functionString=@“var nodeList=document.getElementsByTagName('link');
对于(变量i=0;i
请注意

public MainPage()
{
    this.InitializeComponent();

    MyWebView.LoadCompleted += MyWebView_LoadCompleted;
}

private async void MyWebView_LoadCompleted(object sender, NavigationEventArgs e)
{
     string functionString = @"var nodeList = document.getElementsByTagName ('link');
for (var i = 0; i < nodeList.length; i++)
{
    if ((nodeList[i].getAttribute('rel') == 'icon') || (nodeList[i].getAttribute('rel') == 'shortcut icon'))
    {
        favicon = nodeList[i].getAttribute('href');
        window.external.notify(favicon); 
    }
}";

 await MyWebView.InvokeScriptAsync("eval", new string[] { functionString });

}

private void MyWebView_ScriptNotify(object sender, NotifyEventArgs e)
{
   var url = e.Value;
}
在Package.appxmanifest的Content URIs部分中指定了允许的,并且不能包含域通配符,并且必须是https

这是你可以参考的

从webview UWP获取favicon

html中有用于描述favicon的
快捷方式图标
rel属性。您可以使用WebView
InvokeScriptAsync
将检测到的方法注入eval函数,并使用
window.external.notify
将favicon的href传回

例如

public MainPage()
{
    this.InitializeComponent();

    MyWebView.LoadCompleted += MyWebView_LoadCompleted;
}

private async void MyWebView_LoadCompleted(object sender, NavigationEventArgs e)
{
     string functionString = @"var nodeList = document.getElementsByTagName ('link');
for (var i = 0; i < nodeList.length; i++)
{
    if ((nodeList[i].getAttribute('rel') == 'icon') || (nodeList[i].getAttribute('rel') == 'shortcut icon'))
    {
        favicon = nodeList[i].getAttribute('href');
        window.external.notify(favicon); 
    }
}";

 await MyWebView.InvokeScriptAsync("eval", new string[] { functionString });

}

private void MyWebView_ScriptNotify(object sender, NotifyEventArgs e)
{
   var url = e.Value;
}
public主页()
{
this.InitializeComponent();
MyWebView.LoadCompleted+=MyWebView\u LoadCompleted;
}
私有异步void MyWebView_加载已完成(对象发送方,NavigationEventArgs e)
{
string functionString=@“var nodeList=document.getElementsByTagName('link');
对于(变量i=0;i
请注意

public MainPage()
{
    this.InitializeComponent();

    MyWebView.LoadCompleted += MyWebView_LoadCompleted;
}

private async void MyWebView_LoadCompleted(object sender, NavigationEventArgs e)
{
     string functionString = @"var nodeList = document.getElementsByTagName ('link');
for (var i = 0; i < nodeList.length; i++)
{
    if ((nodeList[i].getAttribute('rel') == 'icon') || (nodeList[i].getAttribute('rel') == 'shortcut icon'))
    {
        favicon = nodeList[i].getAttribute('href');
        window.external.notify(favicon); 
    }
}";

 await MyWebView.InvokeScriptAsync("eval", new string[] { functionString });

}

private void MyWebView_ScriptNotify(object sender, NotifyEventArgs e)
{
   var url = e.Value;
}
在Package.appxmanifest的Content URIs部分中指定了允许的,并且不能包含域通配符,并且必须是https


这是你可以参考的。

我解决了它。我做了以下工作:

Uri icoURI = new Uri("https://www.google.com/s2/favicons?domain=" + WebPageView.Source);
currentTab.IconSource = new Microsoft.UI.Xaml.Controls.BitmapIconSource() { UriSource = icoURI, ShowAsMonochrome = false };

我解决了。我做了以下工作:

Uri icoURI = new Uri("https://www.google.com/s2/favicons?domain=" + WebPageView.Source);
currentTab.IconSource = new Microsoft.UI.Xaml.Controls.BitmapIconSource() { UriSource = icoURI, ShowAsMonochrome = false };

谢谢你的帮助!但是,我已经解决了,忘了更新。谢谢你的帮助!但是,我已经解决了它,忘记了更新。