Delphi、EmbeddedWB/TWebbrowser - jQuery 未执行
我正在使用 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
切换到 Google 托管的 jQuery,但这也不起作用。删除元标记也没有修复它。只是让您知道我在您浪费时间建议之前尝试过的东西:)
EDIT5:通过导航到使用 jQuery (Webbrowser.Navigate) 的网站,该网站按预期工作。但是,当从我的本地 test.html 执行此操作或通过执行 .LoadFromString();
时,它将不起作用。
不起作用 = jQuery 代码不执行。
I am using EmbeddedWB (A TWebbrowser extension) to do like a "live preview" of some dynamically generated content.
I am trying to add jQuery into the mix, so I can get some fancy effects going on, however since IE9 always asks "Allow blocked content" for each and every damn page, a dynamically generated one (Webbrowser.LoadFromString) certainly wont be allowed to have fun. To put it simple: It wont allow Javascript execution.
I tried adding a SecurityManager to my TEmbeddedWB, however that did not do it either. I tested my dynamic code in Firefox, and in IE9, and it works (of course, in IE9 I have to allow first, which was how I found it was a security issue).
Is there a painless way to get around this, without having to manually go into IE and tweak something? Or am I completely wrong about the cause of the issue?
EDIT: After trying this article's method, IE does not ask if it should allow stuff anymore, however my script is still not being executed within my TEmbeddedWB/TWebbrowser..
EDIT 2: Okay, by removing the jQuery code, and displaying a plain Alert, I am forced to conclude that JS is now being executed, however jQuery is not.
EDIT 3: Here is the (stripped down) HTML code that my app generates, where jQuery is not working in my EmbeddedWB/TWebbrowser control - however, it works in Internet Explorer 9 itself:
<!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: I have also tried switching the src
to a Google Hosted jQuery, and that did not work either. Removing the Metatag did not fix it either. Just letting you know of stuff I tried before you waste time on suggesting it :)
EDIT5: By navigating to a site that uses jQuery (Webbrowser.Navigate) the site was working as expected. However when doing it from my local test.html, or by doing .LoadFromString();
, it will not work.
Will not work = jQuery code not executing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它似乎可以工作
如果你为 jquery.js 文件使用正确的 URL或相对路径,
,你也可以省略
file://
协议:当你从文件加载 HTML 时,上面的工作原理。然而问题是,来自内存的内容和来自文件系统的 javascript 是否不被视为跨越安全上下文边界并因此被嵌入式浏览器拒绝。在这种情况下,直接在 HTML 内容中嵌入 jquery(使用标记)应该可以。
It seems to work if you use correct URL for the jquery.js file:
or a relative path, you can also omit the
file://
protocol: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.