搜寻其他网站的搜寻框 [英] Search box that searches another site

查看:78
本文介绍了搜寻其他网站的搜寻框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网站A:开发中(PHP) 网站B: http://www.apprenticesearch.com/

Site A: in development (PHP) Site B: http://www.apprenticesearch.com/

我想在站点A上包含一个输入框;在我键入查询并按Enter后,打开一个新选项卡以显示B的搜索结果.这就像我直接在B中键入搜索查询一样.

I want to include an input box on site A; after I type in the query and press Enter, open a new tab to display the search results of B. It would be as if I had typed the search query into B directly.

例如,我搜索了测试",然后检查了B的搜索结果,我看到了以下内容.如何将查询从站点A传递到站点B?

For example I searched for 'testing', and inspecting the search result from B, I see the following. How would I pass the query from site A to B?

<div id="search">
   <form action="/Resources/SiteSearch" id="siteSearchForm" method="post">
      <label for="search-box">
      SEARCH</label>
      <div id="search-box-wrapper">
         <input type="text" id="search-box">
      </div>
      <input id="searchText" name="searchText" type="hidden" value="testing"><input id="siteSearchUrl" name="siteSearchUrl" type="hidden" value="http://yboss.yahooapis.com/ysearch/limitedweb?format=xml&amp;sites=www.apprenticesearch.com&amp;q=testing">
      <input type="image" src="/userfiles/images/E/buttons/go.png" id="search-button" value="GO" siteurl="www.apprenticesearch.com"><!-- www.apprenticesearch.com -->
   </form>
</div>

推荐答案

您需要做的就是在站点A的表单中包含target ="_ blank",这也是该请求在站点B上的工作方式,即siteSearchUrl输入必须包含

All you need to do is include a target="_blank" in the form on Site A, also the way that the request works on site B the siteSearchUrl input must be included

<form id="apprenticeForm" action="http://www.apprenticesearch.com/Resources/SiteSearch" method="POST" target="_blank" onsubmit='submitSearch()'>
    <input type="text" name="searchText" id="searchText" value=""/>
    <input type="submit" value="Submit"/>
    <input id="siteSearchUrl" name="siteSearchUrl" type="hidden" value="http://yboss.yahooapis.com/ysearch/limitedweb?format=xml&sites=www.apprenticesearch.com&q="/>
</form>

类似于 http://jsfiddle.net/MVBLc/

在处理表单提交之后,但站点B未能读取q参数,我认为这是因为输入转义了&amp;而不是'&'.

After playing around with the form submitting, but the q parameter not being read by Site B, I believe it's because the input had escaped &amp; instead of '&'.

我已经更新了HTML,这是在提交表单之前更新字段的javascript

I've updated the HTML, and here's the javascript to update the field before submitting the form

function submitSearch()
{
    q = document.getElementById("searchText").value;
    document.getElementById("siteSearchUrl").value = 'http://yboss.yahooapis.com/ysearch/limitedweb?format=xml&sites=www.apprenticesearch.com&q=' + q; 
    return true;
}

演示

您需要使用javascript作为额外输入的原因与网站B使用javascript填充其脚本在发送请求之前.

The reason you need to use javascript for the additional input is the same reason why Site B uses javascript to populate siteSearchUrl in their script before it sends the request.

查看服务器的工作方式:站点B将该请求发送到/Resources/SiteSearch,在此服务器上调用SiteSearch(String searchtext, String siteSearchUrl)函数.如果您不带帖子参数而直接进入该页面,则会发现由于未从服务器设置siteSearchUrl而抛出System.ArgumentNullException Parameter name: uriString.

Looking at how the server works: Site B sends that request to /Resources/SiteSearch where the SiteSearch(String searchtext, String siteSearchUrl) function gets called on their server. If you were to just go straight to that page with no post parameters you will find that a System.ArgumentNullException Parameter name: uriString is thrown for not having siteSearchUrl set from the server.

如果要分析siteSearchUrl的参数:

If you want to analyze the parameters of siteSearchUrl:

  • URL yboss.yahooapis.com用于雅虎的BOSS API服务
  • sites参数告诉API搜索哪个网站并在结果中显示
  • q参数是要搜索的查询
  • The URL yboss.yahooapis.com is for Yahoo's BOSS API servcie
  • The sites parameter tells the API what site to search and display in the results
  • and the q parameter is what query to search for

这篇关于搜寻其他网站的搜寻框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆