英文:
how to set --allow-file-access-from-files to cefsharp wpf?
问题
Here is the translated code portion you provided:
我想测试Cefsharp,但我不知道在哪里设置--allow-file-access-from-files。
我已经尝试过以下代码:
<Window x:Class="Chromium.MainWindow"
xmlns:cef="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Chromium"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<cef:ChromiumWebBrowser x:Name="browser" IsBrowserInitializedChanged="browser_IsBrowserInitializedChanged"></cef:ChromiumWebBrowser>
</Grid>
</Window>
private void browser_IsBrowserInitializedChanged(object sender, DependencyPropertyChangedEventArgs e)
{
browser.LoadUrl("file:///C:/index.html");
}
但这并不起作用... 是否有接受本地文件的解决方案?
在本地文件index.html中,我正在使用d3.son()(d3.js库)加载本地json文件(json文件与index.html位于同一文件夹中):
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
:
:
var link = svg.append("g").selectAll(".link"),
node = svg.append("g").selectAll(".node");
d3.json("flare.json", function (error, classes) {
:
这是您提供的代码的翻译部分。
英文:
i would test Cefsharp, but i dont see where to set --allow-file-access-from-files
i have tried
<Window x:Class="Chromium.MainWindow"
xmlns:cef="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Chromium"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<cef:ChromiumWebBrowser x:Name="browser" IsBrowserInitializedChanged="browser_IsBrowserInitializedChanged"></cef:ChromiumWebBrowser>
</Grid>
</Window>
private void browser_IsBrowserInitializedChanged(object sender, DependencyPropertyChangedEventArgs e)
{
browser.LoadUrl("file:///C:/index.html");
}
but its no good.. is there a solution to accept local file?
inside the local file index.html, i am loading a local json file (json in same folder than index.html) with d3.son() (library d3.js)
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
:
:
var link = svg.append("g").selectAll(".link"),
node = svg.append("g").selectAll(".node");
d3.json("flare.json", function (error, classes) {
:
The error displayed:
"Access to XMLHttpRequest at 'file:///C:/flare.json' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, chrome, https, chrome-untrusted.", source: file:///C:/index.html (0)
i have no problem to call from Process.Start:
var p = System.Diagnostics.Process.Start("chrome.exe", "\"file:///C:/index.html\" --allow-file-access-from-files");
答案1
得分: 0
在构造函数中执行以下操作:
var settings = new CefSettings();
settings.CefCommandLineArgs.Add("allow-file-access-from-files");
settings.CefCommandLineArgs.Add("allow-universal-access-from-files");
Cef.Initialize(settings);
英文:
In fact its easy:
just do that in the constructor:
var settings = new CefSettings();
settings.CefCommandLineArgs.Add("allow-file-access-from-files");
settings.CefCommandLineArgs.Add("allow-universal-access-from-files");
Cef.Initialize(settings);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论