$ in IFrame

Prototype $ method works well on parent page. However, if it has an IFrame, what happend to $ method? I have tested it here and here

One of my friend suggested to overcome the situation and shared me the code by which you can extend $ method of prototype in Iframe. He could not tell me the source but after searching a lot, I found that from here

 Demonstration

Try with $(element).hide()

<--- it works in IE8/FireFox

How about Element.hide(element)? [if you already pressed the above, you need to refresh the page to see the following in action]

<--- it also works in IE8 & FireFox (as usual)

 Code I used here

    <script type="text/javascript">
        // Extend prototype's Method avaialble for IFrame
        Prototype.extendFrame = function(element) {
            element = $(element);
            for (var m in Element.Methods) {
                if (Object.isFunction(Element.Methods[m])) {
                    element.contentWindow.Element.prototype[m] = Element.Methods[m].methodize();
                }
            }
        }
    </script>
    

 Finally what I understand

Now, I am happy that I can use prototype $ method in IFRAME using the above method.

1 Responses to "Prototype Dollar ($) in Iframe"

Leave a Reply




Privacy Policy | Terms of use
css template ready for  n°web
© 2008 2009 2010 by http://nazmulweb.com