0

IFrameable コンテンツを作成しています。ユーザーがこのページを IFrame できるようにしたいのですが、ドメインのセット リストからのみです。

親ページのドメイン名を確認するために確認できることはありますか?

if (top != self) { top.location.replace(self.location.href); }
4

3 に答える 3

2

いいえ、locationそのページがセキュリティ コンテキスト内にない場合、親ページは表示されません (同一オリジン ポリシー)。もちろんdocument.referrer、自分のフレームのフレーム内のリフレッシュ フォワーダー。

Content Security Policyframe-ancestors制限により、これが許可される日が来るかもしれません。

于 2009-12-03T03:03:06.550 に答える
2

ボビンスが言っdocument.referrerたように、あなたの最善の策のようです. iFrame の src となるページでこれを確認します。ただし、HTTP リファラー情報は簡単に偽装できるため、この方法はあまり安全ではありません。

この記事では、PHP を使用してそれを行う方法を示します: REFERER セキュリティ チェックをバイパスする方法

于 2009-12-03T04:42:44.373 に答える
1

これを使用して、ページがホワイトリスト ドメインから読み込まれているかどうかを確認しています。これを回避する方法があると確信していますが、うまくいくようです。

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";
   }
}
于 2015-05-15T19:31:42.797 に答える