XHTMLforum

XHTMLforum (http://xhtmlforum.de/index.php)
-   Javascript & Ajax (http://xhtmlforum.de/forumdisplay.php?f=83)
-   -   DIV-Container aus iFrame hängen (http://xhtmlforum.de/showthread.php?t=73415)

bmaniac 21.01.2018 15:21

DIV-Container aus iFrame hängen
 
Hallo,

ich habe ein Problem mit einem JS und stehe hier irgendwie auf dem Schlauch. Ich versuche das Problem mal etwas vereinfacht darzustellen.

Im Firebug habe ich den folgenden Code

HTML-Code:

<html>
  <body>
      ......
      <iframe id="masterFrame">
        <html>
            <body>
                <iframe id="slaveFrame">
                    <html>
                      <body>
                          <!-- SOME CODE -->
                          <div id="myDiv">
                                <!--- SOME CODE -->
                          </div>
                      </body>
                    </html>
                </iframe>
            </body>
        </html>
      </iframe>
      ......
  </body>
</html>

Ich möchte nun den DIV-Container aus dem iFrame "slaveFrame" mittels JS "herausheben", was mit folgendem JavaScript wunderbar funktioniert-

HTML-Code:

<html>
  <body>
      ......
      <iframe id="masterFrame">
        <html>
            <body>
                <iframe id="slaveFrame">
                    <html>
                      <body>
                          <!-- SOME CODE -->
                          <div id="myDiv">
                              <!--- SOME CODE -->
                              <script>
                                var myDiv = document.getElementById("myDiv");
                                window.frameElement.parentNode.appendChild(myDiv);
                              </script>
                          </div>
                      </body>
                    </html>
                </iframe>
            </body>
        </html>
      </iframe>
      ......
  </body>
</html>

Das funktioniert auch problemlos, der Code sieht anschließend im Firebug wie folgt aus:

HTML-Code:

<html>
  <body>
      ......
      <iframe id="masterFrame">
        <html>
            <body>
                <iframe id="slaveFrame">
                    <html>
                      <body>
                      </body>
                    </html>
                </iframe>
                <div id="myDiv">
                  <!--- SOME CODE -->
                  <script>
                      var myDiv = document.getElementById("myDiv");
                      window.frameElement.parentNode.appendChild(myDiv);
                  </script>
                </div>
            </body>
        </html>
      </iframe>
      ......
  </body>
</html>

Mein Problem ist, ich will es noch einmal machen und aus dem masterFrame hängen und das will nicht klappen :| Also ein erneutes

HTML-Code:

window.frameElement.parentNode.appendChild(myDiv);
funktioniert nicht. Wo liegt mein Denkfehler ?

Danke

cloned 22.01.2018 14:42

Sind alle iframes von der selben domain?

bmaniac 22.01.2018 23:13

Hi,

ja sind sie.

Grüße


Alle Zeitangaben in WEZ +2. Es ist jetzt 03:25 Uhr.

Powered by vBulletin® Version 3.8.11 (Deutsch)
Copyright ©2000 - 2024, vBulletin Solutions, Inc.

© Dirk H. 2003 - 2023