我正在创建一个高级搜索,用于搜索特定 Google 云端硬盘文件夹中列出的文件的标题和内容中的术语/单词。搜索本身运行良好,但是当我尝试在 Google 网站上创建搜索框时,当我按 Enter 时,它会在新选项卡中弹出搜索,但它也会弹出一个只是白屏的 Google 网站、atari-embeds.googleusercontent.com。我不确定这是否只是你在 Google 中无法解决的问题,或者搜索框的代码是否有问题。
<div class='advSearch'>
<link href='https://fonts.googleapis.com/css?family=Nunito' rel='stylesheet'>
<style>
body {
font-family: 'Nunito';font-size: 18px;
}
</style>
<form>
<input type="text" id='search' onkeypress="handle(runSearch())" />
<button onclick='runSearch()' style='padding:5px;font-size:10px'>🔍</button>
</form>
<script>
function onkeypress(runSearch()) {
if(event.key === "Enter"){
alert("Enter was pressed")
preventDefault();
</script>
<script>
function runSearch() {
let q = document.getElementById("search").value;
window.open('https://script.google.com/a/macros/LINKHIDDENFORPRIVACYPURPOSES/dev/exec?q='+q);
}
</script>
无需测试按键输入。
如果必须,请使用提交事件。
但是为什么不没有脚本呢?
您打开的窗口将被广告拦截器拦截,但这个不会
(代码片段将在 SO 处被阻止,但不会在您的服务器上被阻止)
body {
font-family: 'Nunito';
font-size: 18px;
}
<link href='https://fonts.googleapis.com/css?family=Nunito' rel='stylesheet'>
<form id="searchForm" target="_blank" action="https://script.google.com/a/macros/LINKHIDDENFORPRIVACYPURPOSES/dev/exec">
<div class='advSearch'>
<input type="text" id="q" value="" />
<button style='padding:5px;font-size:10px'>🔍</button>
</div>
</form>