为自定义网站创建JavaScript搜索框,创建显示搜索结果的弹出窗口

Creating JavaScript search boxes for custom sites that create popup windows showing the search results

本文关键字:创建 搜索结果 显示 窗口 网站 自定义 JavaScript 搜索      更新时间:2023-09-26

我想创建一个JavaScript,将搜索框添加到HTML页面,然后通过输入,它首先对其进行URL编码并将其添加到URL(例如。,http://www.ncbi.nlm.nih.gov/pubmed?term=可以是基本URL)并创建打开结束URL(即URL编码输入和基本URL的添加结果)的新弹出窗口。例如,如果PubMed搜索的输入(与上述示例中的URL相同)是nicotine[TI] AND review[PT],则新窗口将打开的输出URL将是:http://www.ncbi.nlm.nih.gov/pubmed?term=nicotine%5BTI%5D+AND+审阅%5BPT%5D。

尝试

 var Form = $("#myForm");   
 Form.onsubmit = function() {
 var baseUrl = 'http://www.ncbi.nlm.nih.gov/pubmed?term=';
 var search = $("#input").val();
 var Url = baseUrl + search ;
 var encodedUrl = encodeURIComponent(Url);
 var w = window.open(encodedUrl ,'Popup','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=500');
 this.target = 'Popup';
 alert(encodedUrl);
};
<form id="myForm" >
 <input type="text" id="input">
 <button type="submit" >Submit</button>
</form>