简体   繁体   中英

Set Link as Active by Default

I have 3 links that represent the content for one iFrame in my page. When you click each link, it'll reload the contents of that iFrame without reloading the page.

How do i set one link to be active/selected by default, cause what's happening now is the page loads, but still i have to click on the link before the content of the iFrame loads?

here's my code:

            <div id="tabs">
                <div id="overview">
                     <a id="overviewtab" target="tabsa" href="toframe.html">Overviews</a>
                </div>
                <div id="gallery">
                     <a target="tabsa" href="tawagpinoygallery.html">Gallery</a>
                </div>
                <div id="reviews">
                     <a target="tabsa" href="trframe.html">Reviews</a>
                </div>
            </div>
            <div id="tabs-1">
                <!--<div id="scroller">-->
                <iframe name= "tabsa" width="95%" height="100%" frameborder="0"></iframe>
            </div>

thanks so much!! :)

You simply set the src attribute of the iframe to the desired url:

<div id="tabs-1">
<!--<div id="scroller">-->
  <iframe src="toframe.html" name= "tabsa" width="95%" height="100%" frameborder="0"></iframe>
</div>

You can click on a link using JavaScript, eg in the onload attribute of <body> .

A better solution, though, would be to just load the default document into the iframe right away by specifying <iframe src="toframe.html" ...>

如果您有固定的页面开始,请将iframe代码更改为:

<iframe src="toframe.html" name= "tabsa" width="95%" height="100%" frameborder="0"></iframe>

The simplest is to set the src attribute of your iframe to the default content:

<!-- default content is toframe.html -->
<iframe name="tabsa"
        width="95%"
        height="100%"
        frameborder="0"
        src="toframe.html"
></iframe>

Can't you set the value of the iframe's href attribute to the default link? This wouldn't make the link 'active' per say but it would load something when you first log in and allow the frame to load the other links as well.

You might also be able to use javascript to 'click' the link once the window is loaded. I believe this code would look something like function init() = { a.click(); } window.onload = init();

However I'm forced to ask why you would want to make such a sparse page so complicated with the iframe interaction; most people nowadays have a fast enough internet connection that we don't need to code like that. Even if you are targetting low-bandwidth markets the page doesn't seem to have enough content to warrant framing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM