WebBrowser控件不适用于某些javascript构造 [英] WebBrowser control does not work with some javascript constructs

查看:241
本文介绍了WebBrowser控件不适用于某些javascript构造的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现WebBrowser控件(Winforms和WPF)都不支持某些javascript构造,尤其是当使用showModalDialog / showModelessDialog调用渲染它们时....



这很容易重现...



1)创建一个测试html页面,例如 C:\Temp \ Test.htm 使用此代码..

 < input type = button 
onclick =showModalDialog('C :\\Temp\\Test.htm');
value =将我显示为模态页面。 />
< BR />
< a href =javascript:alert('我显示。')>
我应该使用href工作。
< / a>
< BR />
< a href =#
onclick =javascript:alert('我被显示。')>
我应该使用onclick工作。
< / a>

如果使用IE浏览器加载上面的页面,两个超链接都应该有效。现在在IE浏览器中,如果您单击将我显示为模态页面。按钮,同一页面打开为MSHTML对话框窗口,并再次打开两个超链接工作。



这是预期的。



2)现在创建一个 WPF WinForm 应用托管 WebBrowser 控制来源于C:\ Temp \ Test.htm

 < WebBrowser Source =C:\\ \\Temp\Test.htmHeight =500Width =500/> 

如果您运行应用程序并使用 WebBrowser加载测试页控制,两个超链接都适用于加载的页面。



如果您使用将我显示为模态页面加载模态窗口。按钮,然后模态窗口失败使用第一个超链接警告,即 我应该使用href工作。 不会出现。



第二个超链接按预期工作。



你们认为是否有第一个超链接的解决方法工作?



在我的情况下,我无法访问我使用 javascript加载的页面内容:showModalDialog()电话,所以问题修复的目的是从网络浏览器的角度来看。



编辑



<他们说必须为此启用 FEATURE_SCRIPTURL_MITIGATION 。但它已在我的注册表中启用。 MSDN继续说......


默认情况下,为Internet Explorer启用此功能,对于托管该功能的应用程序禁用
WebBrowser 控件。必须手动为
webBrowser 控件启用。


如何为此启用此功能网页浏览器控件?

解决方案

MSDN


此功能 WebBrowser
Control 的应用程序,<不支持。



i have found that WebBrowser control (both Winforms and WPF) has certain javascript constructs not supported especially when they are rendered using showModalDialog / showModelessDialog calls....

This is easily reproducible...

1) Create a test html page such as C:\Temp\Test.htm with this code..

    <input type=button
           onclick="showModalDialog('C:\\Temp\\Test.htm');"
           value="Show Me as Modal Page." />
    <BR />
    <a href="javascript:alert('I am shown.')">
       I should work using href.
    </a>
    <BR />
    <a href="#"
       onclick="javascript:alert('I am shown.')">
       I should work using onclick.
    </a>

If you load the page above using the IE browser, both hyperlinks should work. Now in the IE browser, if you you click the "Show Me as Modal Page." button, the same page opens as MSHTML dialog window and again on that both hyperlinks work.

This is expected.

2) Now create a WPF or WinForm app hosting WebBrowser control sourced to "C:\Temp\Test.htm"

    <WebBrowser Source="C:\Temp\Test.htm" Height="500" Width="500"/>

If you run the app and load the test page using the WebBrowser control, both hyperlinks will work on the loaded page.

But if you load the modal window using the "Show Me as Modal Page." button, then the modal window fails to alert using the first hyperlink i.e. I should work using href. does not appear.

Second hyperlink works as expected.

Do you guys reckon is there a workaround for the first hyperlink to work?

In my case I have no access to the page's content that I am loading using the javascript:showModalDialog() call, so the issue fix is intended from the web browser's perspective.

EDIT

They say that FEATURE_SCRIPTURL_MITIGATION has to be enabled for this. But it is already enabled in my registry. The MSDN continues to say ...

By default, this feature is enabled for Internet Explorer and disabled for applications hosting the WebBrowser Control. It has to be manually enabled for webBrowser control.

How to enable this for the web browser control?

解决方案

MSDN :

This feature is not supported for applications hosting the WebBrowser Control.

这篇关于WebBrowser控件不适用于某些javascript构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆