OK, this is about as close as it is going to get. Everything works as expected until you start hitting the browser's back button after loading various content into the iframes. Then, whatever iframe was active the last time a link was clicked is the one that will go 'back'. Also if a site in a given iframe has code on it to break out of frames on its links (as Yahoo does with some, if not all of their links) it will break out of the iframe but, that was true of the original script too. The checkbox to break out of iframes doesn't work right (it will break out to the original page for the given tab) but, I can probably fix that or it can be taken out. Here is what I have so far:
Code:
<html>
<head>
<title>Tabbed Doc Memory - Demo</title>
<style type="text/css">
/*Eric Meyer's based CSS tab*/
#tablist{
padding: 3px 0;
margin-left: 0;
margin-bottom: 0;
margin-top: 0.1em;
font: bold 12px Verdana;
}
#tablist li{
list-style: none;
display: inline;
margin: 0;
}
#tablist li a{
text-decoration: none;
padding: 3px 0.5em;
margin-left: 3px;
border: 1px solid #778;
border-bottom: none;
background: white;
}
#tablist li a:link, #tablist li a:visited{
color: navy;
}
#tablist li a:hover{
color: #000000;
background: #C1C1FF;
border-color: #227;
}
#tablist li a.current{
background: lightyellow;
}
.tabcurrent{
display:block;
}
.tabbkgrnd{
display:none;
}
</style>
<script type="text/javascript">
/***********************************************
* Tabbed Document Viewer script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
var selectedtablink=""
var tcischecked=false
function handlelink(aobject, frameNum){
selectedtablink=aobject.href
tcischecked=(document.tabcontrol && document.tabcontrol.tabcheck.checked)? true : false
if (document.getElementById && !tcischecked){
var tabobj=document.getElementById("tablist")
var tabobjlinks=tabobj.getElementsByTagName("A")
for (i=0; i<tabobjlinks.length; i++)
tabobjlinks[i].className=""
aobject.className="current"
dispFrames=document.getElementsByTagName('iframe');
for (i = 0; i < dispFrames.length; i++)
if(dispFrames[i].className=='tabcurrent')
dispFrames[i].className='tabbkgrnd'
document.getElementById("tabiframe"+frameNum).className='tabcurrent'
if (document.getElementById("tabiframe"+frameNum).src==''||document.getElementById("tabiframe"+frameNum).src==location.href)
document.getElementById("tabiframe"+frameNum).src=selectedtablink
return false
}
else
return true
}
function handleview(){
tcischecked=document.tabcontrol.tabcheck.checked
if (document.getElementById && tcischecked){
if (selectedtablink!="")
window.location=selectedtablink
}
}
</script>
</head>
<body>
<ul id="tablist">
<li><a class="current" href="http://www.google.com" onClick="return handlelink(this, 0)">Google</a></li>
<li><a href="http://www.yahoo.com" onClick="return handlelink(this, 1)">Yahoo</a></li>
<li><a href="http://www.msn.com" onClick="return handlelink(this, 2)">MSN</a></li>
<li><a href="http://www.news.com" onClick="return handlelink(this, 3)">News.com</a></li>
<li><a href="http://www.dynamicdrive.com" onClick="return handlelink(this, 4)">Dynamic Drive</a></li>
</ul>
<iframe class="tabcurrent" id="tabiframe0" src="http://www.google.com" width="98%" height="350px"></iframe>
<iframe class="tabbkgrnd" id="tabiframe1" src="" width="98%" height="350px"></iframe>
<iframe class="tabbkgrnd" id="tabiframe2" src="" width="98%" height="350px"></iframe>
<iframe class="tabbkgrnd" id="tabiframe3" src="" width="98%" height="350px"></iframe>
<iframe class="tabbkgrnd" id="tabiframe4" src="" width="98%" height="350px"></iframe>
<form name="tabcontrol" style="margin-top:0">
<input name="tabcheck" type="checkbox" onClick="handleview()"> Open tab links in browser window instead.
</form>
</body>
</html>
Bookmarks