当我在我的网站上运行此脚本时,搜索有效,但是当您单击 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>
找到更好的解决方案 如果您需要,请联系我