jquery - External HTML file in Bootstrap Popover content -
when use iframe load external html file in popover content, restricting popup height. want popup height auto. 1 me out .!
$(document).ready(function(){ $('.pop-right').popover({ title : 'loading external file', html : true, placement : "right", content: function () { return '<iframe src="popover-content.html" style="border:none"></iframe>'; }); } }); });
when not cross-domaining', i.e. not loading google.com or similar iframe, relatively easy.
declare below function, takes popover element (.pop-right) , popover content <iframe> parameters :
function adjustpopover(popover, iframe) { var height = iframe.contentwindow.document.body.scrollheight + 'px', popovercontent = $(popover).next('.popover-content'); iframe.style.height = height; popovercontent.css('height', height); } 1) scrollheight of iframe (the real height)
2) .popover-content <div> associated .pop-right
3) set .popover-content real height, , same <iframe> avoid scrollbars.
then, in popover initialisation call adjustpopover() in iframes onload-event onload="adjustpopover(".pop-right", this);" :
$('.pop-right').popover({ title : 'loading external file', html : true, placement : "right", content: function() { return '<iframe src="content.html" style="border:none" onload="adjustpopover(".pop-right", this);"></iframe>'; } }); it idea set minimum height iframes. if dont that, popovers have @ least browsers default height of iframe, in chrome 150px.
iframe { height: 40px; min-height : 40px; } here jsfiddle example loading jsfiddle file /css/normalize.css -> http://jsfiddle.net/ovky3796/
as see, changes .popover max-width in demo. demonstration only, if want adjust width of popover according content of <iframe>, same above scrollwidth instead.
Comments
Post a Comment