我在 Windows 商店开发 (Windows 8) 中使用 HTML/Javascript 在 IFrame 中加载本地 HTML 文件。我正在尝试从 Iframe 获取 Swipe 事件。
我试过这个sample & this .我休假了包含一个 div 元素的鼠标滚轮场景。 对于 Iframe,它不起作用。
我的代码:
<body>
<iframe id="iframe_Id" src="split.html" style="height:768px; width:1366px;" onload="Load();"></iframe>
</body>
function Load() {
var elt = document.getElementById("iframe_Id");
elt.style.backgroundColor = "#f3f3f3";
var gobj = new MSGesture();
// Defining gesture object for Pen, mouse and touch
gobj.target = elt;
elt.gesture = gobj;
elt.gesture.pointerType = null;
// Creating event listeners for gesture elements
elt.addEventListener("MSPointerDown", onPointerDown, false);
elt.addEventListener("MSGestureTap", onTap, false);
elt.addEventListener("MSGestureHold", onHold, false);
elt.addEventListener("MSGestureChange", onGestureChange, false);
// Mouse Wheel does not generate onPointerUp
elt.addEventListener("MSGestureEnd", onGestureEnd, false);
}
function onPointerDown(e) {
var content = document.getElementById("iframe_Id");
}
我为所有事件创建了函数。但是当在我的 IFrame 中滑动时,事件没有引发。 我在这里构造。我需要使用 Swipe。请帮助我摆脱困境。
最佳答案
如果 split.html 是一个本地文件,您应该从 iframe
中监听事件。然后,您可以使用 parent.postMessage()
与主机/父 HTML 页面进行通信。
或者,您可以调查 new WebView control适用于 Windows 8.1 中的 HTML/JavaScript 应用。
关于javascript - 从 iframe 检测滑动手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19655247/