このスクリプトを自分のWebサイトで実行すると検索は機能しますが、iframe内のリンクをクリックするとiframeが消えます。私のウェブサイトhttp://gigster.webege.comで実際の実例を見るには; 右上隅にあるテキストボックス。
<script>
mouseover = false;
function searchFocus() {
i = document.getElementById("searchResults");
i.style.display = "block";
i.onmousemove = function () {
mouseover = true;
}
i.onmouseout = function () {
mouseover = false;
}
}
function searchBlur () {
if (mouseover) {
return;
}
document.getElementById("searchResults").style.display = "none";
}
function querify(query) {
return query.split(" ").join("+") // replaces spaces with +s for url
}
function updateIframe(query) {
query = querify(query);
var i = document.getElementById("searchResults");
var searchEngine = "http://startpage.com/do/m/mobilesearch/?q="
var yourSiteToSearch= "site:example.com+"
i.src = searchEngine + yourSiteToSearch + query;
</script>
<body>
<input oninput="updateIframe(this.value)" onBlur = "searchBlur()" onFocus = "searchFocus(this)" size="31" maxlength="255" style="height: 24px;" placeholder="Search..." type="text">
<iframe id="searchResults" style="display:none;background-color:white;" height="100%" width="100%"></input></iframe>
</body>
あなたがそれを必要とするならば、より良い解決策を見つけてください私に連絡してください