やりたいこと
iframeのページにサイト外部から直接アクセスされてしまう事を防ぐ。URLにアクセスされたらリダイレクトされるようにする。
手順
1. headタグ内に以下のjavascript関数を設定
template.html
<script type="text/javascript"><!--
function open_in_child(n){
if (n == 0 && top.location.href == self.location.href){
//トップページのURLに変更
top.location.href='/index.html';
}
n++;
}
// --></script>
2. bodyタグで実行
template.html
<body onLoad="open_in_child(0)">
以上。リダイレクト先のURLは適宜変更する。これで直接アクセスできないようになる。