• 0

<body onload ="?"> =)


Question

Hi I've been playing around with a tabs script from Dynamic Drive.

It does exactly what I need except that I want a specific tab to be shown when the page loads.

Right now I can control which tab by having ?tab='number' at the end of the URL but there must be a way of putting that into the body tag.

Does anyone know how?

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Hi I've been playing around with a tabs script from Dynamic Drive.

It does exactly what I need except that I want a specific tab to be shown when the page loads.

Right now I can control which tab by having ?tab='number' at the end of the URL but there must be a way of putting that into the body tag.

Does anyone know how?

IIRC body/document/window load is handled a bit differently between browsers.

I would insert an inline script at the bottom of your page before the closing </body> tag:

&lt;script type='text/javascript'&gt;
         //script
&lt;/script&gt;

Of course if you are using the jQuery library you can do something like:

   $(function() { //script } );

which will execute when everything has loaded, the first method will load near enough when the DOM has finished loading, which should be fine.

Link to comment
Share on other sites

  • 0

I already have something similar to what you said.

At the bottom of my HTML page I have :

<script type="text/javascript">

var tabs=new ddtabcontent("tabs")

tabs.setpersist(true)

tabs.setselectedClassTarget("link")

tabs.init()

</script>

Is it simply a matter of adding something to that?

Link to comment
Share on other sites

  • 0

I already have something similar to what you said.

At the bottom of my HTML page I have :

<script type="text/javascript">

var tabs=new ddtabcontent("tabs")

tabs.setpersist(true)

tabs.setselectedClassTarget("link")

tabs.init()

</script>

Is it simply a matter of adding something to that?

Yes. There should be a method inside the class to set the currently selected tab. You'll have to figure this out and put it after tabs.init() i'm assuming.

Link to comment
Share on other sites

  • 0

I found this method in the script.

urlparamselect:function(tabinterfaceid){

var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL

return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index

},

and I tried adding this to the script at the bottom of my HTML page but no luck.

tabs.urlparamselect("?flowertabs=2")

What is it that I'm doing wrong?

Link to comment
Share on other sites

  • 0

I figured out a work around but if anybody has a solution to my problem I'd still like to see it. =)


&lt;head&gt;

&lt;script src="path.to.js" &gt;&lt;/script&gt;
&lt;script&gt;
function LoadTabs() {
    //do stuff
}
&lt;/script&gt;
&lt;/head&gt;

&lt;body onload ="LoadTabs()"&gt;

&lt;/body&gt;

Why don't you try out jQuery?

Link to comment
Share on other sites

  • 0

The tabs I'm using dont load the content of each tab until its selected.

For future reference, this is possible using jQuery UI and it from the code examples shown here it looks loads better:

http://jqueryui.com/demos/tabs/

You also get content loading via Ajax. It's quite a hefty library but can be cusomtised to only include what you require. Infact you can link it straight from google's CDN so users may not even have to download the library.

If you plan on using heavy Javascript I would definately recommend jQuery + jQuery UI.

That function looks a bit hefty for the required task, if the tabs script is not obfuscated or minimised it may be wise to look inside it to see if there is any direct setSelectedTab or something similar.

Cheers,

MiG

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.