$ in IFrame

Prototype $ method works well on parent page. However, if it has an IFrame, what happend to $ method, let s check it.

The above test is already done in here

This time the Iframe's src page contains the prototype.js within script tag. Let us see it in action.

 Demonstration

Try with $(element).hide()

<--- it works in 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">
            Event.observe(window, 'load', function() {
                $('cmdHide').observe('click', function() {
                    //hide element in Iframe
                    try {
                        getEleInIFrame('para').hide();
                    }
                    catch (error) {
                        $$(".notice")[0].update(error).show();
                    }
                });

                $('cmdHide2').observe('click', function() {
                    //hide element in Iframe
                    try {
                        Element.hide(getEleInIFrame('para'));
                        $$(".notice")[0].update("congratulations!!!").show();
                    }
                    catch (error) {
                        $$(".notice")[0].update(error).show();
                    }
                });
            });
            //Get the element in Iframe
            function getEleInIFrame(tgtID) {
                var theFrame = $('ifr');
                var theDoc = theFrame.contentWindow.document;
                var theEle = theDoc.getElementById(tgtID);
                return theEle;
            }

</script>
        

 Finally what I understand

$(element).hide() and Element.hide(element) both work in FireFox whereas the first one does not work in IE8.There is no problem to add the prototype.js in the source file but I myslef do not like to load the script twice as protoype.js by itself size is too big and for slower Internet connection it will be ...(I dont need to say).

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

  1. Great information. Lucky me I found your website by accident (stumbleupon). I’ve book-marked it for later!
  2. It’s hard to find well-informed people in this particular topic, however, you sound like you know what you’re talking about. Thanks!
  3. I have read your article, it is very informative and helpful for me.I admire the valuable information you offer in your articles. Thanks for posting it.
  4. Thanks for a marvelous posting! I definitely enjoyed reading it, you’re a great author. I will ensure that I bookmark your blog and will come back sometime soon. I want to encourage that you continue your great work, have a nice day!
  5. Well, This is a great source. But I hope you keep posting and updating this site. Have a great day.

Leave a Reply




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