Ilian
Ilian

Reputation: 297

JS and Body(Window) Onload event

I have a problem with onload event. My page have 4 iframes and the function from onload event is called 5 times ( one for body and 4 for iframes ). I want only 1 time ( from main body ). Try with srcElement and target property from windows.event but no result... Is there a way to stop onload when iframes load?

Code:

<body onload="init()">

<div id="dialogs">

<div id="login">
        <FORM id="loginform" name="loginform"  action="alogin.php" method="post" target="login_target">...</FORM>
    <iframe id="login_target" name="login_target" src="#"></iframe>  
</div>
...
...
</body>

all Iframe have the same code like this in code. i try to use a code from http://dean.edwards.name/weblog/2005/09/busted/ to check done but the init function is called five times again

Upvotes: 1

Views: 252

Answers (1)

hbw
hbw

Reputation: 15750

You want to check if the current window is the topmost window, which you find by checking against window.top:

function init()
{
    if (this === window.top)
    {
        // This is the main body (not in an iframe)
    }
}

Upvotes: 1

Related Questions