Need help removing an element within an iframe.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RussellReal
    New Member
    • Jun 2007
    • 4

    Need help removing an element within an iframe.

    ok, lets say my main page "testingiframe. html" has this code in it:

    <html>
    <body>
    <iframe id="frame" src="testingsec ondframe.html">
    </body>
    </html>

    and inside "testingsecondf rame.html" has this code in it:

    <html>
    <body>
    <table>
    <tr><td>go go go go go</td></tr>
    <tr><td><ifra me id="frame" src="unwanted_p age_lol.html"></td></tr>
    </table>
    </body>
    </html>

    how would I remove that iframe...

    i tried this:

    <script type="text/javascript">
    var x = document.getEle mentById("frame ").contentDocum ent;
    x.getElementsBy TagName("iframe ")[0].parentNode.rem oveChild(x);
    </script>

    and:

    <script type="text/javascript">
    var x = document.getEle mentById("frame ").contentDocum ent;
    x.getElementsBy TagName("iframe ")[0].src = "nopage.htm l";
    </script>

    and even to see if it was even getting the array:

    <script type="text/javascript">
    var x = document.getEle mentById("frame ").contentDocum ent;
    alert(x.getElem entsByTagName(" iframe").length );
    </script>

    but all of those attempts didn't do much, I am so frustrated its unbelievable. If anybody could help me, it'd be greatly appreciated. Thanks guys.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    Try: [CODE=javascript]x.document.getE lementsByTagNam e("body")[0].removeChild(x. document.getEle mentById("frame "));[/CODE]

    Comment

    • RussellReal
      New Member
      • Jun 2007
      • 4

      #3
      No dice, doesn't work in FireFox or Microsoft IE. Thanks though :(

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Instead of using contentDocument , just use the object itself or access the iframe as a normal using frames["framename"] syntax (but you have to give your iframes names) - see link.

        Comment

        • RussellReal
          New Member
          • Jun 2007
          • 4

          #5
          None of these help, i've tested everything,
          don't worry guys its not so important just I reallllly wanted to get rid of an iframe inside a page, i read that whole page and also tried all the examples and none worked in IE or firefox, i'll keep checking this topic tho maybe someone finds a way to do it that'll work in IE or FireFox (those are the two browsers I use to test my website since they're the most popular).

          thanks again for all your help guys. (and girls)

          Comment

          • Logician
            New Member
            • Feb 2007
            • 210

            #6
            ok, lets say my main page "testingiframe. html" has this code in it:

            <html>
            <body>
            <iframe id="frame" src="testingsec ondframe.html">
            </body>
            </html>

            and inside "testingsecondf rame.html" has this code in it:

            <html>
            <body>
            <table>
            <tr><td>go go go go go</td></tr>
            <tr><td><ifra me id="frame" src="unwanted_p age_lol.html"></td></tr>
            </table>
            </body>
            </html>

            how would I remove that iframe...
            Code:
            var ifToGo=document.getElementById('frame').document.getElementById('frame');
            ifToGo.parentNode.removeChild(ifToGo);
            I don't know why that gap is appearing, it's not there in the source. Just another freshly-introduced bug I expect, like those unwanted line numbers that end up in the Mozilla clipboard.

            Comment

            • RussellReal
              New Member
              • Jun 2007
              • 4

              #7
              That didn't work either, however i tried it a different way and success :D


              Code:
              <script type="text/javascript">
                function checking() {
                  var ifToGo = frames['world'][0];
                  ifToGo.location="";
                }
              </script>
              takes away the annoying flash ads that lag me to hell =\


              thanks again everybody! you guys got me thinking and I put together what everybody said and some of my own lil bit of effort, thanks alot! :D

              Comment

              • Logician
                New Member
                • Feb 2007
                • 210

                #8
                Originally posted by RussellReal
                That didn't work either
                That is the way to do it and it does work, provided that the content of the frame is on the same domain. Is that not the case here?
                I don't think your solution is going to remove the element.
                takes away the annoying flash ads that lag me to hell =\
                I hope you're not trying to suppress content that you have agreed to allow to be shown.

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Originally posted by Logician
                  I don't know why that gap is appearing, it's not there in the source. Just another freshly-introduced bug I expect, like those unwanted line numbers that end up in the Mozilla clipboard.
                  Yes, those gaps have been there for some time, unfortunately.

                  As for the new line numbers bug, I was going to direct you to the Feedback thread, but I see that you've already posted there.

                  Comment

                  Working...