0

我们最近将 Google 上的搜索引擎更新为自定义搜索。它在 Chrome、Firefox 和 Safari 上运行良好,但搜索字段窗口不会出现在 IE8 和 IE9 中。我检查了 CSS 看看这是否是问题,但似乎不是问题。

这是他们希望我们使用的脚本,没有人看到为什么它不会出现在 IE 中的问题吗?

<!-- The following javascript appears before the closing </head> tag. -->
<script>
(function() {
var cx = '012938749785999463601:bae5a4ajf2q';
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
    '//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
})();
</script>
<!-- This tag is inserted where the search box should render -->
 <gcse:searchbox-only></gcse:searchbox-only>

这是一个网站页面:http ://amazingribs.com/tips_and_technique/index2.html

此代码适用于所有其他浏览器。有任何想法吗?

谢谢

4

1 回答 1

2

您可以尝试将代码移动到<body>标签内的某处吗?

您在<head>标签中有它,但它指的是document,在脚本执行时它可能还没有“准备好”。通过将其放置在 中<body>document应该可用。

另外,我会尝试改变这个:

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);

仅此:

document.body.appendChild(gcse);

于 2012-12-31T03:14:57.693 回答