dispatchEvent in iframe

Discuss building things with or for the Mozilla Platform.
Locked
nfr
Posts: 1
Joined: December 21st, 2011, 4:06 pm

dispatchEvent in iframe

Post by nfr »

Hi, I am trying to do a slides viewer working with google doc.
I just put the doc link in a iframe a with prev/next buttons I want to control.
So the idea is to simulate key press : 'n' for next and 'p' for previous

Code: Select all

<html>
<head>
   <title>Slides viewer</title>
   <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
    
   <script type="text/javascript">
      $(document).ready(function() {
         $("#prev").click(function() {
            pressKey(112);
         });
         $("#next").click(function() {
            pressKey(110)
         });
      });
      
      function pressKey(code){
         console.log('press='+code);
         var evt = document.createEvent("KeyboardEvent"); // or KeysEvent
         evt.initKeyEvent("keypress",true,true,null,false,false,false,false,code,code);
         // Send to label   
         var myLabel = document.getElementById('myLabel');
         myLabel.focus()
         myLabel.dispatchEvent(evt);   
         // Send to slides
         var slides = document.getElementById('slides');
         slides.focus()
         slides.dispatchEvent(evt);   

      }
   </script>
</head>
<body>
   <input id="prev" type="button" value="<"/>
   <input id="next" type="button" value=">"/>
   <input id="myLabel" type="input" value=""/>
       <iframe src="https://docs.google.com/present/view?id=0AX5OB7HMRFTQZDR3czVwal8yMjdmdG0zOTljOQ" id="slides"
            width="100%"
              height="100%"
              scrolling="auto"
              frameborder="0"
              />
              
 </body>


I put a label just to verify events are well.
When I click on buttons, the label is fill but the slides don't change. However, if I just press 'n' or 'p', it's work because the iframe have focus.
Any idea ?
peter.kehl
Posts: 7
Joined: July 16th, 2008, 6:30 am
Location: Vancouver, Canada
Contact:

Re: dispatchEvent in iframe

Post by peter.kehl »

Hi NFR,

I've got a similar problem with .dispatchEvent(evt) on an element inside an iframe. Have you figured this out, please?
User avatar
DanRaisch
Moderator
Posts: 127240
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: dispatchEvent in iframe

Post by DanRaisch »

I doubt that nfr will answer after not following up on their original post of three years ago.

Locking this due to the age of the original posts. If you require support please create a new topic.
Locked