IFrameable コンテンツを作成しています。ユーザーがこのページを IFrame できるようにしたいのですが、ドメインのセット リストからのみです。
親ページのドメイン名を確認するために確認できることはありますか?
if (top != self) { top.location.replace(self.location.href); }
IFrameable コンテンツを作成しています。ユーザーがこのページを IFrame できるようにしたいのですが、ドメインのセット リストからのみです。
親ページのドメイン名を確認するために確認できることはありますか?
if (top != self) { top.location.replace(self.location.href); }
いいえ、location
そのページがセキュリティ コンテキスト内にない場合、親ページは表示されません (同一オリジン ポリシー)。もちろんdocument.referrer
、自分のフレームのフレーム内のリフレッシュ フォワーダー。
Content Security Policyのframe-ancestors
制限により、これが許可される日が来るかもしれません。
ボビンスが言っdocument.referrer
たように、あなたの最善の策のようです. iFrame の src となるページでこれを確認します。ただし、HTTP リファラー情報は簡単に偽装できるため、この方法はあまり安全ではありません。
この記事では、PHP を使用してそれを行う方法を示します: REFERER セキュリティ チェックをバイパスする方法
これを使用して、ページがホワイトリスト ドメインから読み込まれているかどうかを確認しています。これを回避する方法があると確信していますが、うまくいくようです。
var currentUrl = document.referrer;
var okayUrl = "http://good-domain.com";
var okayUrl2 = "http://another-good-domain.com";
//check if page is loaded in iframe
if ( window.location !== window.parent.location ) {
//check if parent is a whitelisted domain
if (currentUrl == okayUrl || currentUrl == okayUrl2)
{
//if it is a good domain, then just log the parent url or something
console.log(currentUrl);
} else {
//if it is a bad domain, then do something about it
alert ("Woah buddy. Can't touch this!");
window.location = "http://en.wikipedia.org/wiki/Rickrolling";
}
}