Toon posts:

[js] Kan geen Events toevoegen aan een IFRAME

Pagina: 1
Acties:

Verwijderd

Topicstarter
/Edit
Het betreft Mozilla, probeer de code maar niet in IE, want dat werkt toch niet ;)

Wanneer je een IFRAME aanmaakt met de DOM functies (createElement en appendChild) dan schijnt het onmogelijk te zijn om events toe te voegen. Neem onderstaande code:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<html>
  <head>
    <script>
      function foo() {
        alert('foo');
      }

      function init() {
        /**
         * Create a new IFRAME Element and Append it to the body...
         */
        var oFrame = document.createElement("IFRAME");
        document.body.appendChild(oFrame);
        oFrame.id = "frame";
        
        /**
         * Try to add a mousedown event to the IFRAME. Result: nothing, you can click what you
         * want but no Alert message pops up as expected. :?
         */
        document.getElementById("frame").contentWindow.document.addEventListener("mousedown", foo, true);
      }
    </script>
  </head>
  <body onload="init();">
    Click on the IFRAME and see what happens (check also the sourcecode)<br>
  </body>
</html>


Je kan klikken tot je een ons weegt, maar de onmousedown event wordt niet gevuurt...

Wanneer je gewoon de IFRAME tag gebruikt werkt het wel. Voor beide voorbeeldjes zie:

http://www.nextavenue.com/mozilla/bug/iframe/

[ Voor 11% gewijzigd door Verwijderd op 05-03-2004 15:54 ]


Verwijderd

Probeer dit eens:
document.getElementById("frame").contentWindow.addEventListener("mousedown", foo, true);

  • BtM909
  • Registratie: Juni 2000
  • Niet online

BtM909

Watch out Guys...

dat document kan weg uit:

contentWindow.document.addEventListener

edit:

Niet alleen spuit 11, maar ook fokkin' 5 minuten later |:(

[ Voor 41% gewijzigd door BtM909 op 05-03-2004 16:08 ]

Ace of Base vs Charli XCX - All That She Boom Claps (RMT) | Clean Bandit vs Galantis - I'd Rather Be You (RMT)
You've moved up on my notch-list. You have 1 notch
I have a black belt in Kung Flu.


Verwijderd

Topicstarter
Werkt ook niet...

  • BtM909
  • Registratie: Juni 2000
  • Niet online

BtM909

Watch out Guys...

Bij mij wel :?

Het enige wat ik trouwens ook aangepast hebt, is het id wat je aan je iFRAME gaf.

Volgens mij is frame een reserved woord.

edit:

Voor de volledigheid, dit werkt dus gewoon in Moz:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<html>
  <head>
    <script>
      function foo() {
        alert('foo');
      }

      function init() {
        /**
         * Create a new IFRAME Element and Append it to the body...
         */
        var oFrame = document.createElement("IFRAME");
        document.body.appendChild(oFrame);
        oFrame.id = "BtM909";
        
        /**
         * Try to add a mousedown event to the IFRAME. Result: nothing, you can click what you
         * want but no Alert message pops up as expected. :?
         */
        document.getElementById("BtM909").contentWindow.addEventListener("mousedown", foo, true);
      }
    </script>
  </head>
  <body onload="init();">
    Click on the IFRAME and see what happens (check also the sourcecode)<br>
  </body>
</html>

[ Voor 62% gewijzigd door BtM909 op 05-03-2004 16:12 ]

Ace of Base vs Charli XCX - All That She Boom Claps (RMT) | Clean Bandit vs Galantis - I'd Rather Be You (RMT)
You've moved up on my notch-list. You have 1 notch
I have a black belt in Kung Flu.


Verwijderd

Topicstarter
Krijg nou tieten :S

  • BtM909
  • Registratie: Juni 2000
  • Niet online

BtM909

Watch out Guys...

( . ) ( . )*

;)


* © FoOL

[ Voor 15% gewijzigd door BtM909 op 05-03-2004 16:43 ]

Ace of Base vs Charli XCX - All That She Boom Claps (RMT) | Clean Bandit vs Galantis - I'd Rather Be You (RMT)
You've moved up on my notch-list. You have 1 notch
I have a black belt in Kung Flu.


Verwijderd

Topicstarter
lol

Hij gaat weer vervelend doen als je de designMode op "on" zet... Jij enig idee waarom hij dan geen Events wil attachen?

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<html>
  <head>
    <script>
      function foo() {
        alert('foo');
      }

      function init() {
        /**
         * Create a new IFRAME Element and Append it to the body...
         */
        var oFrame = document.createElement("IFRAME");
        document.body.appendChild(oFrame);
        oFrame.id = "BtM909";
        document.getElementById("BtM909").contentDocument.designMode = 'On';
        /**
         * Try to add a mousedown event to the IFRAME. Result: nothing, you can click what you
         * want but no Alert message pops up as expected. :?
         */
        document.getElementById("BtM909").contentWindow.addEventListener("mousedown", foo, true);
      }
    </script>
  </head>
  <body onload="init();">
    Click on the IFRAME and see what happens (check also the sourcecode)<br>
  </body>
</html>

[ Voor 79% gewijzigd door Verwijderd op 05-03-2004 17:02 ]


Verwijderd

Ik denk dat je een timer erin moet bouwen, zoiets ongeveer:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<html>
  <head>
    <script>
      function foo() {
        alert('foo');
      }

      function init() {
        /**
         * Create a new IFRAME Element and Append it to the body...
         */
        var oFrame = document.createElement("IFRAME");
        document.body.appendChild(oFrame);
        oFrame.id = "BtM909";
        document.getElementById("BtM909").contentDocument.designMode = 'On';
        /**
         * Try to add a mousedown event to the IFRAME. Result: nothing, you can click what you
         * want but no Alert message pops up as expected. :?
         */
        setTimeout(doe2,100);
      }
            function doe2(){
            document.getElementById("BtM909").contentWindow.addEventListener("mousedown", foo, true);
            }
    </script>
  </head>
  <body onload="init();"><button onclick="doe2()">doe2</button>
    Click on the IFRAME and see what happens (check also the sourcecode)<br>
  </body>
</html>

Om een of andere reden heeft Mozilla een adempauze nodig.

Verwijderd

Topicstarter
Ode aan Martijn

_/-\o_

Raar maar waar, je heb helemaal gelijk, nu ga ik tot op de bodem uitzoeken waar dit op slaat :)

Verwijderd

Gesubmit door de topic starter, wellicht interessant: http://bugzilla.mozilla.org/show_bug.cgi?id=236547
Pagina: 1