locked
MSGesture events from Iframe in WinJs

    Question

  • Hello,


     I am using MsGesture() to get gesture s from my app(HTML/JAVASCRIPT). I working for Swipe gesture from IFrame for few days;

                  var div;
                  var gest;
    
                 gest = new MSGesture();
                //div = document.getElementById("div_Id");
                div = document.getElementById("iframe_Id");
    
                gest.target = div;
                div.gesture = gest;
                div.gesture.pointerType = null;
    
            // Creating event listeners for gesture elements
                div.addEventListener("MSPointerDown", onPointerDown, false);
                div.addEventListener("MSGestureTap", onTap, false);
                div.addEventListener("MSGestureHold", onHold, false);
                div.addEventListener("wheel", onMouseWheel, false);
                div.addEventListener("MSGestureStart", onmsgesturestart, true);
                div.addEventListener("MSGestureChange", onGestureChange, false);
                div.addEventListener("MSGestureEnd", onmsgestureend, false);

      When I work with div It is working fine & getting gestures. If I replace with Iframe it doesn't call any events. 

      I think I am trying to get gesture from Iframe ContentWindow. Please give some time for this suggest me.

       Here is my complete test Code 


    devendra

    • Edited by GDEVENDRAK Monday, November 11, 2013 5:31 PM
    Monday, November 11, 2013 1:22 PM

Answers

  • Why don't you create an initialization function in your split.html that will be invoked when the page is actually loaded rather than trying to execute the script "during" the load of the page when the HTML elements may not be ready for usage.

    Here's a screenshot of what I tried and the approach which does not throw an exception.


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    • Marked as answer by GDEVENDRAK Wednesday, November 20, 2013 7:09 AM
    Tuesday, November 19, 2013 6:32 PM
    Moderator

All replies

  • Hello,

    You will need to put the MSGesture event logic in the actual page - split.html that holds the HTML content inside the <iframe>, rather than the <iframe> itself. An <iframe> is a holder for external content, so you cannot just assign gestures for an iframe and make it available for any HTML page that gets rendered in the <iframe>.

    Thanks,

    Prashant.


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Tuesday, November 12, 2013 12:18 AM
    Moderator

  • @Prashant H Phadke

     
    So, I have to create gesture In iframe. 
    Here I am bot of unclear about how to get elements to create gesture in HTML..?

      var div = document.getElementsByTagName("body"); //getting TypeMismatchError
      

    Image

    Can post relevant link about this..

    Thanks

    devendra



    • Edited by GDEVENDRAK Tuesday, November 12, 2013 2:37 AM
    Tuesday, November 12, 2013 2:25 AM

  • Still I did n't get this one. I tried some ways to create gesture from my HTML loading IFrame as Prashant H Phadke said. Is there any one aware about my situation.

     Any would be appreciated. :)

    devendra

    Friday, November 15, 2013 4:42 PM
  • Why don't you create an initialization function in your split.html that will be invoked when the page is actually loaded rather than trying to execute the script "during" the load of the page when the HTML elements may not be ready for usage.

    Here's a screenshot of what I tried and the approach which does not throw an exception.


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    • Marked as answer by GDEVENDRAK Wednesday, November 20, 2013 7:09 AM
    Tuesday, November 19, 2013 6:32 PM
    Moderator
  •  @Prashant H Phadke


     Thanks for reply, 

       It is working fine. But there is a problem while using 

                      e.target.gesture.pointerType
      There is no gesture property in target;


     So, I tried with some ways & finally I found in "currentTarget"; For me It is working fine in "function OnPointerDown "

            function onPointerDown(e) {
                if (e.currentTarget.gesture.pointerType === null) {                    // First contact
                    e.currentTarget.gesture.addPointer(e.pointerId);                   // Attaches pointer to element (e.target is the element)
                    e.currentTarget.gesture.pointerType = e.pointerType;
                }
                else if (e.currentTarget.gesture.pointerType === e.pointerType) {      // Contacts of similar type
                    e.currentTarget.gesture.addPointer(e.pointerId);                   // Attaches pointer to element (e.target is the element)
                }
            }

    I hope It wont give any problem in future. I am wondering because from Iframe I need to get Horizontal Swipe which have to differ right to left & left to right swipe gestures; 
     Now I will move forward for this;

       If suppose I find any issues there I will  discuss here :)


    devendra


    • Edited by GDEVENDRAK Wednesday, November 20, 2013 7:13 AM
    Wednesday, November 20, 2013 7:08 AM