I have a tabbed container with iframes in each tab (don't scold me... I have no alternative on this one). The contents of each iframe are very large, so when a user selects a different tab, I want the contents (HTML) of the iframe from the 'old' tab to be removed before the new tab and its iframe contents are loaded and displayed. In this way, only ever should the contents of the iframe in the currently selected tab be loaded, while all iframe content in the other tabs is empty. I've researched how to clear iframe contents, but despite my efforts I'm just not able to apply it successfully to the tabs jquery code. Can anyone help? Fiddle: https://jsfiddle.net/kxh47qjo/
https://code.jquery.com/jquery-1.12.4.js
https://code.jquery.com/ui/1.12.1/jquery-ui.js
https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css
<div id="tabs">
<ul>
<li><a class="tabref" href="#tabs-1" rel="https://bing.com">Table1</a></li>
<li><a class="tabref" href="#tabs-2" rel="https://jsfiddle.net">Table2</a></li>
<li><a class="tabref" href="#tabs-3" rel="https://jqueryui.com/demos/tabs">Table3</a>
</ul>
<div id="tabs-1">
</div>
<div id="tabs-2">
</div>
<div id="tabs-3">
</div>
</div>
.
$(function() {
var $tabs = $('#tabs').tabs();
// Select start tab index number
var MASTER_STARTtab = 0;
$("#tabs").tabs({active: MASTER_STARTtab
});
//Get tab contents
beginTab = $("#tabs ul li:eq(" + MASTER_STARTtab + ")").find("a");
loadTabFrame($(beginTab).attr("href"), $(beginTab).attr("rel"));
// -----------------------------------
$("a.tabref").click(function() {
loadTabFrame($(this).attr("href"), $(this).attr("rel"));
});
//tab switching function
function loadTabFrame(tab, url) {
if ($(tab).find("iframe").length == 0) {
var html = [];
html.push('<div class="tabIframeWrapper">');
html.push('<div class="openout"><a href="' + url + '"><border="0"
alt="Open" title="Remove iFrame" /></a></div><iframe class="iframetab" src="' + url + '">Load Failed?</iframe>');
html.push('</div>');
$(tab).append(html.join(""));
$(tab).find("iframe").height($(window).height() - 80);
}
return false;
}
});