0

我想创建一个动态高度 Iframe。

我正在构建一个自定义搜索引擎,我必须在其中使用谷歌搜索数据显示我的数据。

意思是:如果我在搜索文本框中输入“asdq”,那么它将显示我的数据结果和自定义谷歌搜索结果。

我想根据谷歌发送的内容更改 iframe 的高度。意思是:让谷歌发送 10 行然后我的 iframe 大小将是 100 像素,如果谷歌发送 1 数据然后 10 像素等。

如果我修复了 iframe 的高度,那么如果更多数据来自 Google,则滚动条会出现在 iframe 中。

你可以在这里看到我的问题

实际上我想删除 iframe 的滚动条,以便只有一个滚动条是页面滚动条。

请帮忙

提前致谢。

4

1 回答 1

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>
于 2012-12-20T06:52:41.280 回答