我在Windows 7 WPF应用程序中托管WebBrowser控件。
现在我遇到了在此浏览器中运行的javascript的问题。 DOM pointer
事件未触发。当我单击DOM对象时,mousedown
和click
事件会触发,但pointerdown
事件不会触发,即使在Internet Explorer 11中查看同一页面时它也会触发。
如何激活DOM pointerdown
事件?
以下是我在浏览器中看到的内容:
这是我在WPF应用程序中看到的内容:
这是我正在测试的HTML文档:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=11">
<script type="text/javascript" src="./scripts/jquery.min.js"></script>
<title>Raw test page</title>
<style type="text/css">
#mouseTarget{
border: 2px solid purple;
background: steelblue;
font-weight: bold;
width: 300px;
height: 100px;
}
</style>
</head>
<body>
<div id="mouseTarget">Mouse Target</div>
<div id="logOutput"></div>
<script type="text/javascript">
var logOutput = function (text) {
$("<div></div>").text(text).appendTo($("#logOutput"));
};
var mouseTarget = document.getElementById('mouseTarget');
mouseTarget.addEventListener('pointerdown', function () {
logOutput('pointerdown event received');
}, false);
mouseTarget.addEventListener('mousedown', function () {
logOutput('mousedown event received');
}, false);
mouseTarget.addEventListener('click', function () {
logOutput('click event received');
}, false);
</script>
</body>
</html>
答案 0 :(得分:1)
编辑:很抱歉,似乎设置不足以FIRE指针事件。它只是识别触摸事件,但仍然只触发鼠标事件。非常烦人......
问题是WebBrowser控件不像通常的IE实例那样。首先,它默认使用传统的后备IE7模式。其他要点是传统输入模型等等。
我个人有问题将browserMode设置为IE10但指针事件根本不起作用。问题是,WebBrowser控件假装支持我订阅的PointerEvents,但是由于启用了传统输入模型,这些并没有被解雇。
您可以在应用程序中为该应用程序动态设置这些策略:
private void SetBrowserCompatibilityMode()
{
// http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx
// FeatureControl settings are per-process
var fileName = Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);
if (String.Compare(fileName, "devenv.exe", true) == 0) // make sure we're not running inside Visual Studio
return;
using (var key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION",
RegistryKeyPermissionCheck.ReadWriteSubTree))
{
// Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
UInt32 mode = 10000; // 10000; or 11000 if IE11 is explicitly supported as well
key.SetValue(fileName, mode, RegistryValueKind.DWord);
}
using (var key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_NINPUT_LEGACYMODE",
RegistryKeyPermissionCheck.ReadWriteSubTree))
{
// disable Legacy Input Model
UInt32 mode = 0;
key.SetValue(fileName, mode, RegistryValueKind.DWord);
}
}