简体   繁体   English

C# WebBrowser 不加载本地 Javascript 文件

[英]C# WebBrowser not loading local Javascript file

I am using the C# WebBrowser control.我正在使用 C# WebBrowser 控件。 My HTML renders fine.我的 HTML 渲染得很好。 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?如何编写 HTML 来加载本地存储的文件?

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:这在将文件直接加载到浏览器时有效,但不能通过 C# WebBrowser 控件:

<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.我尝试将其添加到 html 文件的第一行,但不能解决问题。

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

Just put your local js file in the same directory with your html file.只需将本地 js 文件与 html 文件放在同一目录中即可。 Then use this will do然后使用这个就可以了

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM