2012-11-07 70 views
0

我想創建一個動態高度Iframe。如何設置跨域的iframe高度

我正在建立一個自定義搜索引擎,我必須在Google搜索數據中顯示我的數據。

意思是:如果我在搜索文本框中輸入「asdq」,那麼它會顯示我的數據結果與自定義谷歌搜索結果。

我想要更改iframe與由Google發送的內容一致的高度。 意思是:讓Google發送10行,然後我的iframe大小將爲100px,如果Google發送1個數據,然後是10px等

如果我修復iframe的高度,那麼滾動條會進入iframe,如果更多數據來自Google。

你可以看到我的問題here

其實我想刪除iframe的滾動條,這樣只有一個滾動條會在那裏是網頁滾動條。

請幫忙

在此先感謝。

+0

看到這個答案:http://stackoverflow.com/a/9163087/1726343 –

+0

不要指定iframe的高度(或設置爲100%),並刪除溢出CSS屬性 – sdespont

+0

我想這

這是行不通的 – bhagirathi

回答

2

如果從其他域獲取數據,我們無法設置Iframe的大小,意味着如果我們無法訪問iframe的正文。

我們可以用這個來形成這個問題。

<script type="text/javascript"> 
    google.load('search', '1'); // loads Google Search library, v 1 
// get a custom search control & keep it in cseControl 
// note: put your own custom search ID number here 
var cseControl = new google.search.CustomSearchControl('009827885688477640989:igzwimalyta'); 
// open pages from search results clicks on the same page 
cseControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF); 
// when there are no matches, explain why 
cseControl.setNoResultsString("Sorry, there are no pages in this web site that match all the search terms."); 
// make the search field visible in div with ID 'cseDiv' 
cseControl.draw('divGoogleResult'); 

cseControl.execute(userInput); 

</script>