2012-08-10 68 views
0

我正在使用從bookmarklet調用的一個iframe,它調用一個html頁面,該頁面顯示有關他們正在查看的頁面的用戶詳細信息。要關閉的iframe我使用:iframe breakout是雙後退按鈕

<a href="<? echo $original_page_url; ?>" target="_parent">X Close Window</a> 

這將關閉iframe和離開他們在同一個頁面上的用戶。然而,對於瀏覽器而言,這是理想的,他們必須兩次按下後退按鈕以回到他們之前的位置,例如,一些搜索結果,因爲它們必須連續兩次到當前頁面。一旦最初,然後再次關閉iframe。

有沒有更好的方法來做到這一點,可以避免這種情況?

這是書籤代碼產卵的iframe:

javascript:(function%20(d)%20{var%20modal%20=%20document.createElement('iframe'); 
modal.setAttribute('src',%20'http://blah.com/info.html?url='+encodeURIComponent(window.location.href)+'&page_title='+document.title); 
modal.setAttribute('scrolling',%20'no');modal.className%20=%20'modal'; 
document.body.appendChild(modal);var%20c%20=%20document.createElement('link'); 
c.type%20=%20'text/css';c.rel%20=%20'stylesheet'; 
c.href%20=%20'//blah.com/css/iframe.css'; 
document.body.appendChild(c);}(document)); 

回答

0

使用此JavaScript代碼:

document.getElementById('iframeId').style.display='none'; 

而且,你可以關閉的iframe這裏面的iframe:

parent.document.getElementById('iframeId').style.display='none'; 

這將從父級獲取iframe對象,並將其可見性設置爲隱藏。

+0

謝謝你,但我不設置的iframe的ID(或者是在的createElement?),這是一種新的我居然,儘可能快地學習 - 修正了這個問題......有沒有一種方法來設置ID(如果不是這樣),然後添加你的建議?我嘗試過:X Close Window但不起作用 – 2012-08-10 22:52:03

0

嘗試window.location.replace

也許這樣

<a onclick="window.location.replace('<? echo $original_page_url; ?>')">X Close Window</a> 
+0

這只是將原始網址與iframe中的內容互換,並將網頁留在那裏 - 並不好。 – 2012-08-11 07:17:44