6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iframeの中身への直接アクセスを回避する

Posted at

やりたいこと

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は適宜変更する。これで直接アクセスできないようになる。

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?