2013-10-29 80 views
4

我使用Windows Store開發(Windows 8)中的HTML/Javascript在IFrame中加載本地HTML文件。我想從Iframe中獲取Swipe事件。檢測iframe中的滑動手勢

我試過這個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。請幫我解決這個問題。

回答

3

你應該把你的一個<div>塊中,像這樣:

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

然後你看在div#watch,而不是iframe輕掃,因爲觸摸事件將在DOM和不在iframe中。

+1

這真的有必要嗎?爲什麼要尋找新的div而不是身體的刷卡? – WoIIe

+0

@Natuu 我做了你的建議。它不工作。我能夠在div上刷卡..但不Iframe – Kumar

5

如果split.html是本地文件,您應該監聽iframe中的事件。然後,您可以使用parent.postMessage()與主機/父級HTML頁面進行通信。

另外,您也可以調查在Windows 8.1中HTML/JavaScript應用程序可用的new WebView control

+0

首先,我很抱歉爲非常晚的答覆。我試圖僅從iframe收聽活動。但我不知道'Parent.postMessage()'。我是Javascript新手。 你能分享任何與我的案例有關的簡要描述的來源鏈接嗎?謝謝 – Kumar

+0

&我想澄清還有一件事是'仍然Webview有像禁用ZOOM'的限制。 SO它不適用於我的情況 – Kumar

+0

現在我正在「傾聽來自IFrame的事件」。 嘗試後我會回到U. – Kumar