同じウィンドウに別フレームを開き、その中のページを入れ替える JavaScript のサンプルです。
サンプルコード ———————————————————————-
index.html
<html><head>
<title>Javascript Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>
<body bgcolor="#FFFFFF" leftmargin="20" topmargin="20" marginwidth="20" marginheight="20">
<p>同じウィンドウに別フレームを開き、その中のページを入れ替える</p>
<p><a href="//www.goo.ne.jp/" target="_top" rel="noopener">http://www.goo.ne.jp/</a></p>
<p><a href="//www.yahoo.co.jp/" target="_top" rel="noopener">http://www.yahoo.co.jp/</a></p>
</body>
frame.html
<html><head>
<title>Javascript Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>
<frameset rows="100,1*">
<frame name="header" src="index.html">
<frame name="main" src="null.html">
</frameset>
<noframes>
<BODY bgcolor="#FFFFFF">
</BODY>
</noframes>
null.html
<html><head>
<title>Javascript Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<script language="JavaScript">
<!--
function loaded(n) {
if (n.length <= 1) {
// location.href = '' ;
parent.top.location.replace('index.html');
} else {
// location.href = n.substring(1,n.length) + '.html' ;
// location.replace(n.substring(1,n.length) + '.html') ;
location.replace(n.substring(1,n.length)) ;
}
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" onload="loaded(top.location.search);">
</body>
実際に動作するサンプル ———————————————————————-
– サンプルファイル