gpt4 book ai didi

javascript - 如何在c#中的wpf webbrowser控件中注入(inject)js文件

转载 作者:搜寻专家 更新时间:2023-11-01 04:36:11 37 4
gpt4 key购买 nike

您好,我在我的 xaml 页面上使用 WPF WebBrowser 控件。我的 html 包中有 Html、Jquery、js 和 css 文件。我必须使用所有 jquery 库在 Web 浏览器控件中加载 html 页面。我怎样才能注入(inject)这个文件?我正在编写这样的代码:

page.xaml.cs

 void wb_Loaded(object sender, RoutedEventArgs e)
{
string htmlPath = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "keyboardWidget\\test.html");
string html = File.ReadAllText(htmlPath.ToString());
webBrowser.NavigateToString(html);

}

这是 page.xaml:

<WebBrowser x:Name="webBrowser"></WebBrowser>

我遇到这样的错误。

enter image description here

您好,谁能建议注入(inject) js 或 jquery 库的最佳方法。如果在 wpf 网络浏览器控件中不可能,那么我应该使用什么控件。

最佳答案

我怀疑问题可能不是 WebBrowser 控件未找到 JS 脚本,而是 WPF WebBrowser 控件与 JSON 存在兼容性问题。

尝试在您的页面中包含此脚本,看看它是否能解决问题: JSON2

下载 json2.js 并将其包含在您页面的 HTML 中:

<script  type="text/javascript" src="json2.js"></script>

关于javascript - 如何在c#中的wpf webbrowser控件中注入(inject)js文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31877256/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com