1

我正在使用 EmbeddedWB(TWebbrowser 扩展)来做一些动态生成内容的“实时预览”。

我正在尝试将 jQuery 添加到组合中,所以我可以获得一些花哨的效果,但是由于 IE9 总是为每个该死的页面询问“允许阻止的内容”,因此肯定不会允许动态生成的页面 (Webbrowser.LoadFromString)找乐子。简而言之:它不允许 Javascript 执行。

我尝试将 SecurityManager 添加到我的 TEmbeddedWB 中,但也没有这样做。我在 Firefox 和 IE9 中测试了我的动态代码,它可以工作(当然,在 IE9 中我必须首先允许,这就是我发现这是一个安全问题的原因)。

有没有一种轻松的方法来解决这个问题,而无需手动进入 IE 并进行一些调整?还是我对问题的原因完全错误?

编辑:在尝试了这篇文章的方法之后,IE 不再询问它是否应该允许东西了,但是我的脚本仍然没有在我的 TEmbeddedWB/TWebbrowser 中执行。

编辑 2:好的,通过删除 jQuery 代码并显示一个普通的警报,我不得不得出结论,现在正在执行 JS,但 jQuery 不是。

编辑 3:这是我的应用程序生成的(精简的)HTML 代码,其中 jQuery 在我的 EmbeddedWB/TWebbrowser 控件中不起作用 -但是,它在 Internet Explorer 9 本身中起作用:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=9" />
    <script type="text/javascript" src="file://C:\jQuery.js"></script>
</head>
<body>
    <center>
    <p>
      Some stuff here!
    </p>
    </center>

    <script type="text/javascript" language="javascript">
    $(document).ready(function(){
            alert('I Am jQuery!!!!');
    });
    </script>
</body>
</html>

EDIT4:我也尝试过切换src到谷歌托管的 jQuery,但这也不起作用。删除 Metatag 也没有修复它。在你浪费时间建议之前让你知道我尝试过的东西:)

EDIT5:通过导航到使用 jQuery (Webbrowser.Navigate) 的站点,该站点按预期工作。但是,当从我的本地 test.html 或通过做.LoadFromString();它时,它将不起作用。

将不起作用 = jQuery 代码未执行。

4

1 回答 1

2

It seems to work if you use correct URL for the jquery.js file:

<script type="text/javascript" src="file://C:/jQuery.js"></script>
<script type="text/javascript" src="file:///jQuery.js"></script>

or a relative path, you can also omit the file:// protocol:

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

The above works when you load the HTML from a file. The question is however, if content from memory and javascript from file system is not considered crossing a security context boundary and rejected for that reason by the embedded browser. In that case, embedding jquery directly in the HTML content (using the <script> tag) should work.

于 2011-07-26T08:34:12.643 回答