4

我在 Windows 商店开发(Windows 8)中使用 HTML/Javascript 在 IFrame 中加载本地 HTML 文件。我正在尝试从 iframe 获取 Swipe 事件。

我试过这个样本这个。我放弃了包含一个 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。请帮我解决这个问题。

4

2 回答 2

5

如果 split.html 是本地文件,您应该从iframe. 然后,您可以使用parent.postMessage()与主机/父 HTML 页面进行通信。

或者,您可以研究适用于 Windows 8.1 中的 HTML/JavaScript 应用程序的新 WebView 控件。

于 2013-11-03T16:33:32.253 回答
1

You should put your <iframe> inside a <div> block, like this :

<body>
   <div id="watch">
       <iframe id="iframe_Id" src="split.html" style="height:768px;
       width:1366px;" onload="Load();">
       </iframe>
   </div>
</body>

And then you look the swipe in the div#watch instead of the iframe, because the touch event will be in the DOM and not in the iframe.

于 2013-11-01T02:18:20.670 回答