![](/img/trans.png)
[英]Get the URL of the webpage displayed in an <object>
[英]How to get a webpage displayed within another webpage?
我正在嘗試使用spring-security框架創建一個Web應用程序“ A”。 驗證后,它將帶用戶到一個頁面,在該頁面中,窗口(可使用iframe實現)中將顯示另一個Web應用程序“ B”(托管在同一服務器/其他服務器上)。 主Web應用程序“ A”從用戶那里獲取Web應用程序“ B”的鏈接地址,因此Web應用程序“ B”應可動態更改。
我創建了具有CAS身份驗證的網絡應用“ A”。 身份驗證后,它將在使用iframe的窗口中顯示Web應用程序“ B”,但是當我嘗試使用jQuery和Javascript動態更改Web頁面“ B”時,它將失敗。
如果有人可以幫助我,我將不勝感激。 首先,請讓我知道我是否做對了,否則建議我采取正確的措施。 還請讓我知道是否有更好的方法可以達到相同目的。 請參見下面的代碼。
謝謝,薩欽
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#serverurl").attr("src", $("#Link").val());
});
});
</script>
</head>
<body>
<h1>Secure Page</h1>
<p>This is a protected page. You can get to me if you've been remembered,
or if you've authenticated this session.</p>
<p><a href="../">Home</a>
<p><a href="../j_spring_security_logout">Logout</a>
<p>Enter URL: <input type="text" id="Link" value="www.google.com"></p>
<button>Show webpage</button>
<div><iframe src="http://w3school.com" id="serverurl" width="800" height="600"></iframe></div>
</body> </html>
我在jsFiddle上重新創建了您的示例:
因此,您有兩個問題:
您的輸入值缺少http://。 因此,您的瀏覽器會嘗試打開一個相對路徑,例如:http: //yourserver.com/www.google.com
如果打開瀏覽器控制台並單擊“顯示網頁”,則會看到類似以下錯誤: Refused to display 'https://www.google.com/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
。 發生這種情況是因為Google服務器發送了標頭,以避免clickjacking攻擊 。
如果您要在iFrame中顯示的所有網站都沒有發送X-Frame-Options
(如google),則只需修復第一個項目,一切就可以了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.