在Onload事件上使用Javascript Action

时间:2015-10-19 19:08:02

标签: javascript iframe onload

我是javascript的新手,无法将我的代码更改为我想要的内容。

<iframe name="hidden_iframe" id="hidden_iframe"
style="display:none;" onload="if(submitted)
{window.location='http://site.html';}"></iframe>

我的意图是使用此window.location(重定向到其他页面)以在同一页面中启动操作。如果是链接,我的代码将是:

<a onClick="OpenSel(1)"></a>

如何在onload事件后使用OpenSel(1)?

谢谢!

1 个答案:

答案 0 :(得分:1)

坚持已经存在的东西:

onload="if (submitted) {window.location='http://site.html';} OpenSel(1)"

虽然如果你把这一切都放在一个函数中可能会更容易:

function loadCheck() {
    if (submitted) {
        window.location='http://site.html';
    } 
    OpenSel(1)
}

onload="loadCheck()"