我想创建一个动态高度的 Iframe。
我正在构建一个自定义搜索引擎,我必须在其中使用谷歌搜索数据显示我的数据。
意思是:如果我在搜索文本框中输入“asdq”,那么它将显示我的数据结果和自定义谷歌搜索结果。
我想根据谷歌发送的内容更改 iframe 的高度。 意思是:让 Google 发送 10 行,那么我的 iframe 大小将为 100px,如果 Google 发送 1 个数据,则为 10px 等。
如果我修复 iframe 的高度,那么如果更多数据来自 Google,滚动条就会出现在 iframe 上。
你可以看到我的问题here
实际上我想删除 iframe 的滚动条,这样只有一个滚动条,即页面滚动条。
请帮忙
提前致谢。
最佳答案
如果 iframe 从其他域获取数据,意味着我们无权访问 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>
关于javascript - 如何设置跨域的iframe高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13268778/