問題描述
如何在頁面加載期間發現我的頁面作為框架嵌入到其他站點?我猜推薦人請求標頭在這里幫不了我?謝謝.
How can I find out that my page is embedded as a frame to other site during page loading? I guess referrer request header can't help me here? Thanks.
推薦答案
你不能從服務器端檢查它,但你可以在頁面加載后使用 javascript 來檢測它.比較top
和self
,如果它們不相同,你就在一個框架中.
You cannot check it from the server's side, but you can use javascript to detect it after the page has loaded. Compare top
and self
, if they're not identical, you are in a frame.
此外,一些現代瀏覽器尊重 X-FRAME-OPTIONS
標頭,它可以有兩個值:
Additionally, some modern browsers respect the X-FRAME-OPTIONS
header, that can have two values:
- DENY - 如果頁面包含在框架中,則防止頁面被呈現
- SAMEORIGIN – 與上述相同,除非頁面與頂級框架集持有者屬于同一域.
用戶包括無法嵌入框架的 Google 的 Picasa.
Users include Google's Picasa, that cannot be embedded in a frame.
支持header的瀏覽器,最低版本:
Browsers that support the header, with the minimum version:
- IE8 和 IE9
- Opera 10.50
- Safari 4
- Chrome 4.1.249.1042
- Firefox 3.6.9(帶有 NoScript 的舊版本)
- IE8 and IE9
- Opera 10.50
- Safari 4
- Chrome 4.1.249.1042
- Firefox 3.6.9 (older versions with NoScript)
這篇關于如何防止我的網站頁面通過 iFrame 的第 3 方網站框架加載的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!