I'm trying to change the location of an adjacent frame on page load with Javascript.
I have a page with a frameset:
<html lang="en">
<HEAD>
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<script type="text/javascript">
function confirm() {
//Code to execute before page close
return '[close message]';
}
window.onbeforeunload=confirm;
</script>
<frameset cols="30%, 70%" FRAMEBORDER=NO FRAMESPACING=0 BORDER=0>
<frame name="leftFrame" src="control.php" scrolling="no">
<frame name="right" id="right" src="q.php">
</frameset>
</head>
</html>
My leftFrame is control.php, which has a form whose action is also control.php:
<!-- sample form on control.php -->
<form method="post" action="control.php">
<input ../>
<input type="submit" />
</form>
The idea is that every time the form is submitted, the right frame is supposed to reload back to q.php:
<script language="javascript">
function refresh() {
parent.right.location.href ="q.php";
}
</script>
</head>
<body onLoad="refresh();">
But this is not working. The right frame stays as is and doesn't change back to q.php. in other words refresh()
isn't working.
Can anyone tell me what I'm doing wrong, or a better way to do this?
instead of onload
i used onsubmit
. my guess is that it wasn't working onload
because the page was already loaded.