2013-11-04 226 views
2

如何在新窗口中打開iframe?我試着用「滾動='自動'」。它不起作用。在新窗口中打開iframe

我把我的代碼在這裏:

<iframe width="572px" scrolling="auto" height="335px" 
     frameborder="1" src="http://XXXX.com/iframe-page" 
     style="border: 0px none #ffffff;" name="national-campaign" 
     marginheight="0px" marginwidth="0px"> 
</iframe> 

任何想法?乾杯。

+2

你能解釋一下多一點,你的意思嗎?你想在新窗口中打開鏈接嗎? iframe是嵌入在另一個頁面中的「窗口」。如果沒有其他頁面,嵌入的概念,因此iframe,似乎沒有多大意義。 –

+0

除非兩個頁面位於同一個域中,否則不能。 – Nathan

+0

是的,我想在新窗口中打開鏈接。我有兩個網站,一個公司網站和一個經銷商網站。在企業網站上,我只有一張圖片,我想在企業網站和經銷商網站上展示圖片。當你點擊圖片時,它會查看詳細信息頁面。然而,我在經銷商網站上想要的是,當您點擊iframe圖片時,它會在新窗口中打開選項卡,而不是在iframe內顯示詳細信息頁面。希望它是有道理的。 –

回答

0

我會建議你只是使用超鏈接到另一個頁面,而不是一個iframe。或者是一個實際上是鏈接的屏幕截圖。

一些用戶可能會'聰明',足以在iframe中(在Internet Explorer中)右鍵單擊並選擇「在新窗口中打開」選項,但其他人不會那樣做。

+0

嗨,我終於在公司網站圖片上使用了'target =「_ top」'。所以代碼是:。 –

+0

或者'target = _blank'來打開一個新窗口:) – kosherjellyfish

+0

但是這是通過超鏈接而不是iframe來完成的 –

0

簡單的方法是使用具有屬性target =「_ blank」的超鏈接。

如果高度和寬度對您很重要(參考您的示例),那麼您可以使用JavaScript方法window.open

1

嘗試在該鏈接內添加target="_top"

,或者如果你需要從一個鏈接打開一個新頁面中的iframe中,如果我的理解或者正確,您可以:

使用jQuery的

$('iframe a').attr('target', '_blank'); 
0

您可以用jQuery做到這一點, window.open方法。

HTML:

<iframe id="iframe" width="572px" scrolling="auto" height="335px" 
     frameborder="1" src="http://XXXX.com/iframe-page" 
     style="border: 0px none #ffffff;" name="national-campaign" 
     marginheight="0px" marginwidth="0px"> 
</iframe> 

JS:

var iframe = $("#iframe"); 
var newWindow = window.open(iframe.attr(src), 'Dynamic Popup', 'height=' + iframe.height() + ', width=' + iframe.width() + 'scrollbars=auto, resizable=no, location=no, status=no'); 
newWindow.document.write(iframe[0].outerHTML); 
newWindow.document.close(); 
iframe[0].outerHTML = ''; // to remove iframe in page. 
+0

你建議的是簡單的js--在父窗口中不會提供給你 - 除非父域對你的iframe的js能力沒有限制,這是不太可能的。 – Ricalsin