C#WebBrowser不加载本地JavaScript文件

发布于 2025-01-29 05:12:01 字数 676 浏览 1 评论 0原文

我正在使用C#WebBrowser控件。我的HTML使得很好。但是,我需要将外部文件保留在本地计算机上。引用文件本地副本不起作用。

如何编写HTML以加载本地存储的文件?

这起作用:

<script type='text/javascript' src='https://code.jquery.com/jquery-latest.min.js'></script>

当将文件直接加载到浏览器中时,这起作用了,但不能通过C#WebBrowser控件:

<script type='text/javascript' src='./jquery-latest.min.js'></script>

添加完整路径可以摆脱错误消息,但仍然不起作用。

<script type='text/javascript' src='file:///C:/<full path>/jquery-latest.min.js'></script>

我尝试将其添加到HTML文件的第一行中,该文件无法解决问题。

<!-- saved from url=(0014)about:internet -->

I am using the C# WebBrowser control. My HTML renders fine. However, I need to keep external files on the local computer. References to the local copy of files do not work.

How do I write the HTML to load locally stored files?

This works:

<script type='text/javascript' src='https://code.jquery.com/jquery-latest.min.js'></script>

This works when loading a file directly in to a browser, but not through the C# WebBrowser control:

<script type='text/javascript' src='./jquery-latest.min.js'></script>

Adding the full path gets rid of error messages, but still does not work.

<script type='text/javascript' src='file:///C:/<full path>/jquery-latest.min.js'></script>

I have tried adding this to the first line of the html file which does not solve the problem.

<!-- saved from url=(0014)about:internet -->

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无戏配角 2025-02-05 05:12:01

只需将您的本地JS文件与HTML文件放在同一目录中。然后使用此操作

<script type='text/javascript' src='./jquery-latest.min.js'></script>

Just put your local js file in the same directory with your html file. Then use this will do

<script type='text/javascript' src='./jquery-latest.min.js'></script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文