[英]Beforeunload is not working to redirect user to another page, how can I redirect user to another page/url when he attempts to close a window/tab?
[英]How can I redirect to another page when an iFrame is detected?
這是測試頁。 我有一個包含iFrame的頁面,該頁面包含我網站上的另一個HTML頁面。
<html>
<head>
<title>Clickjack test page</title>
</head>
<body>
<p>Website is not vulnerable to clickjacking.</p>
<iframe src="../page1" width="500" height="500" id="iframe"></iframe>
</body>
</html>
這是我在page1.html上的腳本
<script type="text/javascript">
console.log(window.location != window.parent.location);
if(window.location != window.parent.location){
console.log("iFrame Detected");
window.location.replace("redirectMessage.html");
window.location.href = "redirectMessage.html";
console.log("after redirect");
}
else {
// no iframe
}
</script>
目標:當我轉到ClickJack測試頁時,檢測一個iframe並將該iFrame中的頁面重定向到redirectMessage.html
我在控制台中after redirect
iFrame Detected
因此,我知道我的IF語句已到達。
但是iFrame中的頁面不會重定向。
您不應該嘗試弄清楚頁面是否正在iframe中加載,因為攻擊者可能只是使用iframe上的sandbox屬性,而這會使腳本停止運行,從而使您的(登錄)頁面容易受到點擊劫持。
相反,您的網站后端應返回X-FRAME-OPTIONS設置為DENY,以阻止瀏覽器在iframe中呈現您的網站。
有關更多詳細信息,請參見此處: https : //steemit.com/security/@gaottantacinque/steemit-security-check-iframe-tricks
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.