SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Disable iframe from my page

    Hi,
    Does anyone know how can make the < iframe > tag not to appear on my pages? even if someone does put it i want it replaced by another word to not function.

    Thank you,

    Mike.

  2. #2
    SitePoint Member
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It can be JS, PHP, whatever works.

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    iframe {display:none}
    This will only work in Opera, AFAIK:
    Code:
    iframe {content:"IFRAME is not supported"}
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Member
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's exactly what i tried doing 4 months ago when i needed it but for some reason it did not work.
    I will try and let you know how it went, big thank you.

  5. #5
    SitePoint Member
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, it did not disable it, it just made it invisible.
    It still loads the page in the background.
    I need something that would completely erase or change the word "iframe" from my PHP page.

  6. #6
    Guru Meditation Error gnarly's Avatar
    Join Date
    Dec 2003
    Location
    Cheltenham, United Kingdom
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why can't you just remove it from the HTML/PHP code?
    Olly Hodgson
    thinkdrastic.net

  7. #7
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Either remove it from the PHP source, or use JavaScript to remove the IFRAME element nodes at runtime.
    Birnam wood is come to Dunsinane

  8. #8
    SitePoint Member
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem, how do i do that?
    use JavaScript to remove the IFRAME element nodes at runtime

  9. #9
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That question belongs in the JavaScript forum, but something like this:
    Code:
    function removeIFrames()
    {
        var f = document.getElementsByTagName("iframe");
        for (var i = 0; i < f.length; ++i) {
            f&#91;i&#93;.parentNode.removeChild(f&#91;i&#93;);
        }
    }
    
    window.addEventListener("load", removeIFrames, false);
    Note that this only works for standards-compliant browsers (Opera, Firefox, probably Safari, Konqueror,...). For IE, you need to use another registration mechanism for the event listener (window.attachEvent()).

    Also note that it only works for HTML (and pretend-XHTML). For real XHTML, you need the namespace-aware function document.getElementsByTagNameNS().

    Thirdly, note that this is completely untested and unlikely to work as-is. Since the return value of document.getElementsByTagName() is a NodeList, which is 'live', it's possible that you should just remove the first node of that list until the list is empty.
    Birnam wood is come to Dunsinane

  10. #10
    SitePoint Member
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really do appreciate the help, however, like you said it does not work on IE.
    I'm no JS professional, can you give me a hint on how to make it work on IE?

  11. #11
    Guru Meditation Error gnarly's Avatar
    Join Date
    Dec 2003
    Location
    Cheltenham, United Kingdom
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As Tommy said, you'd be better off asking in the Javascript forum.
    Olly Hodgson
    thinkdrastic.net

  12. #12
    SitePoint Member
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Posted.
    Thank you.

  13. #13
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by puzo
    I'm no JS professional, can you give me a hint on how to make it work on IE?
    I already did.
    You need to use window.attachEvent() instead of window.addEventListener().

    The latter is in the W3C DOM Level 2 Events recommendation. The former is Microsoft's proprietary function.
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •