2012-02-06 78 views
18

我想在iframe中嵌入網頁,但它根本不起作用。具有相對路徑的內部頁面正常顯示。但這個簡單的代碼不起作用:iframe與外部網頁無法正常工作

<iframe src="http://www.google.com/"></iframe> 

這應該顯示的iframe的地方就是空的。我看了頁面源,並沒有什麼後

這是怎麼回事?

回答

3

因爲內部頁面已經做了一些事情來防止放入iframe。

也許一段JavaScript這樣的

if (window.top != window.self) {window.top.location = window.self.location;} 
-1

假設你的網址是www.google.com,即$ URL = 「www.google.com」;

$headerRes = get_headers($url); //get the header response 

foreach($headerRes as $val) 
    if($val=="X-Frame-Options: SAMEORIGIN" || $val=="X-Frame-Options: DENY"){ 
    header("location:".$url); 
    exit; 
    } 
//simply redirect to their website instead of showing blank frame 

我希望我解釋自己很好。

+0

這兩個問題都沒有要求PHP解決方案,也沒有答案表明您正在使用服務器端解決方案(即PHP)來重定向用戶。 – 2017-04-14 18:14:48