Friday 20 January 2012

Iframe dynamic Height and src url using jquery

Below jquery code will help you to  generate dynamic height without scroll bar in iframe and also you can change src url dynamically. 

$(document)
    .ready(
        function() {
                  var newurl = 'any_url';
            $('#iframe_id').attr('src', newurl);

            // For other good browsers.
            $('iframe')
            .load(
                function() {
                    this.style.height = 0;

                    this.style.height = this.contentWindow.document.body.scrollHeight
                    + 500 + 'px';
                // this.style.width =
                // this.contentWindow.document.body.offsetWidth
                // + 100 + 'px';

                });

        });

Hope this will help :)

Cheers


No comments:

Post a Comment