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 に答える