/    Sign up×
Community /Pin to ProfileBookmark

how to make a default tab? tabs menu with iframes.

Hi, I have developed a tabs menu with iframes.

My problem is, Not able to make a tab active by default.

description:

i have curved-corner tabs. (i am using two gif images. One for left and one for right corner….) Each gif image contains 3 images in it for
active: hover: and visited event. I am using CSS: background-position property to animate the tab( moving control top, bottom and middle on the image which contains 3 images in it).

Problem is: I am not able to make one tab as default tab and position the control over required image. code as follows:

[code]
/*.css file*
.glowingtabs li{
display:inline;
margin:0;
padding:3px 5px 3px 5px;
color: #383838;
font: small-caps 13px Arial, Helvetica, sans-serif;
font-weight: bold;
}

.glowingtabs li a{
float:left;
background:url(img/TabLeft.gif) no-repeat left top;
margin:0;
margin-right: -6px; /*spacing between each tab*/
padding:0 0 0 7px;
text-decoration:none;
}

.glowingtabs a span{
float:left;
display:block;
background:url(img/TabRight.gif) no-repeat right top;
padding:5px 12px 3px 3px;
font-weight:bold;
color:#3B3B3B;
}

/* Commented Backslash Hack hides rule from IE5-Mac */
.glowingtabs a span {float:none;}
/* End IE5-Mac hack */

.glowingtabs a:visited{ /*Selected Tab style*/
background-position:0 0; /*Shift background image up to start of 2nd tab image*/
}

.glowingtabs a:visited span{ /*Selected Tab style*/
background-position:100% 0; /*Shift background image up to start of 2nd tab image*/
}

.glowingtabs a:hover{
background-position:0 -30px;
}

.glowingtabs a:hover span {
background-position:100% -30px;
color: #383838;
}

.glowingtabs a:active{
background-position:0% -60px;
}

.glowingtabs a:active span {
background-position:100% -60px;
color: #FFFFFF;
}
[/code]

[code]
/*html file*/
<HTML>

<HEAD>
<TITLE>tab</TITLE>
<link href=”tab_style.css” rel=”stylesheet” type=”text/css” media=”screen” />
<script type=”text/javascript” src=”tab_test.js”>
</script>
</head>

<body onLoad=”dTab(‘tabIframe’)”>
<div class=”tabBox”>
<div class=”tabarea”>
<div class=”glowingtabs”>
<ul>
<li onClick=”removeDefault()”><a href=”India.html” target=”tabIframe”><span>India</span></a></li>
<li id=”select”><a href=”America.html” target=”tabIframe” rel=”indexTab”><span>America</span></a></li>
<li onClick=”removeDefault()”><a href=”Canada.html” target=”tabIframe”><span>Canada</span></a></li>
</ul>
</div>
</div>
<!———— ————–code for iframes ———————–> <div class=”tabMain”>
<div class=”tabIframeWrapper”>
<iframe class=”tabContent” name=”tabIframe” src=”America.html”>
&nbsp;aaaaaaaaaaa
</iframe>
</div>
</div>
<div>
<!————————–end of iframes————————————>

</BODY>
</HTML>

[/code]

[code]
/*java Script*/
function dTab(frameName){var linkList=document.getElementById(“select”);
if (linkList!=null)
{
alert(“id with select exists”);
linkList.className += ” defaultTab”;
}
}

function removeDefault() {

alert(“witn in removeDefault”);
}
[/code]

I am not able to make default tab with the same properties of .glowingtab:active span{}
i am totally struct. Please help me. I want tab America to have red color image which is in the bottom of 3 imaged gif.

please help me
Regards,
Ash

to post a comment
JavaScript

22 Comments(s)

Copy linkTweet thisAlerts:
@ashviniauthorJan 23.2009 — [COLOR="Red"][B]please help me[/QUOTE][/B][/COLOR]

Regards,

ashu
Copy linkTweet thisAlerts:
@FangJan 23.2009 — #select.defaultTab a span {background:#f00 url(redImage.gif) no-repeat;}
Copy linkTweet thisAlerts:
@ashviniauthorJan 27.2009 — hi Fang,

Thank you so much !! Thanks a ton !! my code is working now.

Default tab is done.

But, my immediate question is:

Once page loads, default tab is activated. Suppose user press India / canada , I want Default property to be removed from America's tab. How to do this??

Please help me

Regards,

Ash
Copy linkTweet thisAlerts:
@ashviniauthorJan 27.2009 — What exactly i want is:

By default, a tab is selected on page load. Once User clicks on other tabs, I want to remove default tab's css class (dynamically from JavaScript). Is there any way out for this??

Please help.

Regards,

Ash
Copy linkTweet thisAlerts:
@FangJan 27.2009 — &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;

&lt;script type="text/javascript"&gt;
function removeDefault(obj) {
for(var i=0; i&lt;tabItems.length; i++) {
tabItems[i].className=''
}
obj.className='select';
}

var tabItems=[];
window.onload=function() {
var fl=frames['tabIframe'].location.href ;
var tabs=document.getElementsByTagName('li')
for(var i=0; i&lt;tabs.length; i++) {
var aList=tabs[i].getElementsByTagName('a');
if(aList.length &amp;&amp; aList[0].getAttribute('target')=='tabIframe'){
tabItems.push(tabs[i]);
tabs[i].onclick=function() {removeDefault(this);};
if(fl.indexOf(aList[0].getElementsByTagName('span')[0].innerHTML)!=-1) {
tabs[i].className='select';
}
}
}
};
&lt;/script&gt;

&lt;style type="text/css"&gt;

.glowingtabs li{
display:inline;
margin:0;
padding:3px 5px 3px 5px;
color: #383838;
font: small-caps 13px Arial, Helvetica, sans-serif;
font-weight: bold;
}

.glowingtabs li a{
float:left;
background:url(img/TabLeft.gif) no-repeat left top;
margin:0;
margin-right: -6px; /*spacing between each tab*/
padding:0 0 0 7px;
text-decoration:none;
}

.glowingtabs a span{
float:left;
display:block;
background:url(img/TabRight.gif) no-repeat right top;
padding:5px 12px 3px 3px;
font-weight:bold;
color:#3B3B3B;
}

/* Commented Backslash Hack hides rule from IE5-Mac */
.glowingtabs a span {float:none;}
/* End IE5-Mac hack */

.glowingtabs a:visited{ /*Selected Tab style*/
background-position:0 0; /*Shift background image up to start of 2nd tab image*/
}

.glowingtabs a:visited span{ /*Selected Tab style*/
background-position:100&amp;#37; 0; /*Shift background image up to start of 2nd tab image*/
}


.glowingtabs a:hover{
background-position:0 -30px;
}

.glowingtabs a:hover span {
background-position:100% -30px;
color: #383838;
}

.glowingtabs a:active{
background-position:0% -60px;
}

.glowingtabs a:active span {
background-position:100% -60px;
color: #FFFFFF;
}

.select a span {background:#f00 url(redImage.gif) no-repeat;}
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;div class="tabBox"&gt;
&lt;div class="tabarea"&gt;
&lt;div class="glowingtabs"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="India.html" target="tabIframe"&gt;&lt;span&gt;India&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="America.html" target="tabIframe" rel="indexTab"&gt;&lt;span&gt;America&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="Canada.html" target="tabIframe"&gt;&lt;span&gt;Canada&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!-- code for iframes --&gt;
&lt;div class="tabMain"&gt;
&lt;div class="tabIframeWrapper"&gt;
&lt;iframe class="tabContent" name="tabIframe" src="America.html"&gt;
&lt;/iframe&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!-- end of iframes --&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@ashviniauthorJan 30.2009 — Hi Fang,

Thanks to your reply.

#select.defaultTab a span {background-positon:100&#37; -60px} is working fine when it is the only one application in a web page. If i add these .js, .css and contents to my main web page, it is not working. Why ? "select" id is unique. I have not used this id for any other control. Why it is not working?
Copy linkTweet thisAlerts:
@FangJan 30.2009 — Give the full code used or a link.
Copy linkTweet thisAlerts:
@ashviniauthorJan 30.2009 — HI Fang,

It is working fine now. But, got a bug:

I have a event calender in my page. It has got provision to navigate to next month from current month. When i click on > button to view next month in the calender, my default tab is getting deactivated.

I want to avoid that. IS there any way to remember status of a default tab.? When i click on any other control in the page, my default tab should not get deactivated. How to do it?

Pls. Help.

Regards,

Ashvini?
Copy linkTweet thisAlerts:
@FangJan 30.2009 — That would only happen if the button opens the calender in the iframe.

The script will only work correctly using the code you gave.
Copy linkTweet thisAlerts:
@ashviniauthorFeb 02.2009 — NO, Actually,

My web page is divided into two parts. Left and right.

It is a tableless-<div> based layout.

In the left-pane, i have this tabbed menu. In the right-pane, I have event calender. There is no connection between tabbed menu and event calender except that they both lie on a common web page.

But when i click on the "Next month" button in event-calender, my default tab is getting deactivated. Wanted to know why.
Copy linkTweet thisAlerts:
@FangFeb 02.2009 — Give a link to the page.
Copy linkTweet thisAlerts:
@ashviniauthorFeb 03.2009 — Hi Fang,

I can't give the link as it is for our company'sinternal use. i will paste you the code.

<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;
&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt; New Document &lt;/TITLE&gt;
&lt;script language="JavaScript" type="text/javascript" src="events.js"&gt;&lt;/script&gt;
&lt;script language="JavaScript" type="text/javascript" src="tab_menu.js"&gt;&lt;/script&gt;
&lt;/HEAD&gt;

&lt;BODY&gt;
&lt;!-- =============== =============== Left Pane contents =============== =============== --&gt;
&lt;div id="CS"&gt;&lt;div id="CSBanner"&gt;&lt;/div&gt;

<i> </i> &lt;div class="tabBox"&gt;
<i> </i> &lt;div class="tabarea"&gt;
<i> </i> &lt;div class="glowingtabs"&gt;
<i> </i> &lt;ul&gt;
<i> </i> &lt;li id="select"&gt;&lt;a href="India.html" target="tabIframe"&gt;&lt;span&gt;India&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
<i> </i> &lt;li onClick="removeDefault()"&gt;&lt;a href="America.html" target="tabIframe" &gt;&lt;span&gt;America&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
<i> </i> &lt;li id="tab3"&gt;&lt;a href="Canada.html" target="tabIframe"&gt;&lt;span&gt;Canada&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
<i> </i> &lt;/ul&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;

<i> </i> &lt;div class="tabMain"&gt;
<i> </i> &lt;div class="tabIframeWrapper"&gt;
<i> </i> &lt;!-- Give default tab's conents link for src--&gt;
<i> </i> &lt;iframe class="tabContent" name="tabIframe" src="India.html" border="0" frameborder="0"&gt;
<i> </i> &lt;/iframe&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;div id="CSFooter"&gt;&lt;/div&gt;

<i> </i> &lt;/div&gt;
&lt;/div&gt;
&lt;!-- =============== =============== =============== =============== =============== --&gt;

&lt;!-- ------------- Calendar Block START ------------- --&gt;
&lt;div id="right"&gt;

<i> </i> &lt;div id="R-Icon"&gt;
<i> </i> &lt;!-- Insert Placeholder Icon path below --&gt;
<i> </i> &lt;img border="0" src="tones.gif"&gt;
<i> </i> &lt;/div&gt;&lt;div id="R-Heading"&gt;
<i> </i> &lt;!-- Insert Heading here --&gt;
<i> </i> Events
<i> </i> &lt;/div&gt;
<i> </i> &lt;center&gt;
<i> </i> &lt;div id="calend"&gt;
<i> </i> &lt;div id="calendar"&gt;&lt;/div&gt;
<i> </i> &lt;form id="eventform" name="eventform" action="#" method="get"&gt;
<i> </i> &lt;div id="tipDiv1"&gt;
<i> </i> &lt;p align=center&gt;&lt;br&gt;
<i> </i> &lt;textarea style="background: #000000; color: #FFFFFF; overflow: hidden; width: 180px; height: 180px; font: 12px Arial, Helvetica, sans-serif; text-align: center;"
<i> </i> name="eventlist" wrap="virtual"&gt;;&amp;nbsp&lt;/textarea&gt;
<i> </i> &lt;br&gt;&lt;br&gt;&lt;/p&gt;&lt;/div&gt;
<i> </i> &lt;/form&gt;
<i> </i> &lt;/div&gt;
<i> </i> &lt;/center&gt;
<i> </i> &lt;/div&gt;
&lt;!-- ------------- Calendar Block END ------------- --&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;

My problem is:

For the first time when page loads, default tabs are activated. If i click on event calender for the first time (without meddling tabs), default tab is not getting disturbed.

But, if i meddle with tabs first and then click on event calender, default tab is getting deactivated. this is the problem. Is there any way to maintain the status of the default tab?

please help

Regards,
Copy linkTweet thisAlerts:
@FangFeb 03.2009 — There's no JavaScript nor css???

You haven't implemented the solution I gave???
Copy linkTweet thisAlerts:
@ashviniauthorFeb 03.2009 — script ->.js file
<i>
</i>function dTab(frameName){
//alert("with in dTab function"+frameName);
var lL=document.getElementById("select");
if (lL!=null)
{
lL.className += "defaultTab";
}
}

function removeDefault() {

<i> </i>var i, curList, newList;
<i> </i>newList = new Array();
<i> </i>var lLi=document.getElementById("select");
<i> </i>if (lLi!=null)
<i> </i>{
<i> </i> lLi.className += "RemoveDefaultTab";
<i> </i>}
}


<i>
</i>stylesheet -&gt; .css file -&gt; along with my first post's code, i have inculded these code also.....I have copied your code's logic and customized it to my program's logic. ....

#select.defaultTab a{
background-position:0 -60px;
border:0px solid white;
color: #FFFFFF;
}

#select.defaultTab a span{
background-position:100% -60px;
border:0px solid Yellow;
}
#select.RemoveDefaultTab a{
background-position:0 0;
color: #FFFFFF;
}

#select.RemoveDefaultTab a span{
background-position:100% 0;
}
Copy linkTweet thisAlerts:
@FangFeb 03.2009 — Only clicking link America will change anything.
Copy linkTweet thisAlerts:
@ashviniauthorFeb 04.2009 — HI Fang,

Thank you for your mail. My problem as follows:

As soon as page loads,

1) When I click on default tab first, Nothing will change in the page.(working fine)

2)When I click on any other tab(except default) first, and then move to event calendar or any other control in the page, which ever tab is active is getting deselected.

3) When page loads, if I click on event calendar first, default tab is not getting affected. (it will be active till I click on it or any other tab--working fine)

Don’t know where it is going wrong.

My expectation is:

1) As soon as page loads, I will click on any other tab (say Canada)..Then I move to event calendar to see events on next month. Even after clicking event calendar, I want tab "Canada" to be active... how to do it???

Please help.?

Regards,
Copy linkTweet thisAlerts:
@ashviniauthorFeb 05.2009 — Fang or Anyone else,

Please help me.


Regards,
Copy linkTweet thisAlerts:
@thebutterflyFeb 11.2009 — Hey There

Great Script! I am just using the basic version you posted in the earliest posts - problem is that for me ie7 is not applying the class. Even IE6 is.... I've reposted the script here:

[CODE] <script type="text/javascript">
/*java Script*/
function dTab(frameName){var linkList=document.getElementById("select");
if (linkList!=null)
{
<!---alert("id with select exists"); --->
linkList.className += "defaultTab";
}
}

function removeDefault() {

<!---alert("witn in removeDefault");--->
}</script>[/CODE]

Please help (IE drives me nuts!)

Thanks
Copy linkTweet thisAlerts:
@seangamerFeb 11.2009 — I've not read everything, sorry, I'm lazy this morning :p

If you are using iframes you could try setting a variable on the parent page to hold the default tab information and then check for it every time the frame loads.

[CODE]parent.variable=defaultTab;[/CODE]
[CODE]<iframe src="SRC" onload="tabCheck();"></iframe>[/CODE]

However, this will only work so long as the iframe is the only page being refreshed. If your main page is refreshed the variable will be reset. If you have to refresh your main page occasionally, then you may want to consider using cookies, or another programming language, such as PHP.

Hope this helps!
Copy linkTweet thisAlerts:
@thebutterflyFeb 11.2009 — hey - thanks for the reply. Let me give you a few cliffs notes so we're on the same page (it may be me who's not on right page ? ) ---

I have the links changing background image on active/visted etc. When you click on a link it keeps the selected frame's active displaying the correct bg image - basic but.. here's been my dilema. I need it so that when the parent page loads for the default link to show the active background. To do this I've used the above script and corrisponding css. This works PERFECT in FF, IE6, Safari, & Chrome. IE7 however hates me ? hehehe and is showing the script there and the ID of the link there but it's not applying the class.

Here:

This again:
[CODE]

<script type="text/javascript">
/*java Script*/
function dTab(frameName){var linkList=document.getElementById("select");
if (linkList!=null)
{
<!---alert("id with select exists"); --->
linkList.className += "defaultTab";
}
}

function removeDefault() {

<!---alert("witn in removeDefault");--->
}</script>[/CODE]


Then the link
[CODE]">
<a id="select" target="homeFrame" href="MY LINK">
<img alt="" border="0" src="MY IMAGE" /></a></[/CODE]


And my CSS

a.defaultTab:link,

a.defaultTab:visited{

background: transparent;

background-image: url(MY BG IMAGE);

height:93px;

width:46px;

display:block;

background-repeat:no-repeat;

}


Can you help?
Copy linkTweet thisAlerts:
@seangamerFeb 11.2009 — I actually meant it to help ashvini, but if it helped you too, that's good too ?

I've only got IE5 and FF2 here at work, so I'm not sure how much I can help right now. I can try to help when I get home though.
Copy linkTweet thisAlerts:
@ashviniauthorFeb 13.2009 — I've not read everything, sorry, I'm lazy this morning :p

If you are using iframes you could try setting a variable on the parent page to hold the default tab information and then check for it every time the frame loads.

[CODE]parent.variable=defaultTab;[/CODE]
[CODE]<iframe src="SRC" onload="tabCheck();"></iframe>[/CODE]

However, this will only work so long as the iframe is the only page being refreshed. If your main page is refreshed the variable will be reset. If you have to refresh your main page occasionally, then you may want to consider using cookies, or another programming language, such as PHP.

Hope this helps![/QUOTE]



Hi seangamer,

Thanks for your post,

i didn't understand where to copy your code..."parent.variable=defaultTab". where to store tabCheck()? what to be written with in it?

pls help

Regards
×

Success!

Help @ashvini spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...