讓你的網站也有Open Search
- 2008-06-16
- 11755
- 0
有使用Firefox3.x和IE7.x以上的網友都知道右上角的搜尋列一直是一個相當好用的東西,也有不少套件對它琢磨,本篇文章教您如何把自己的網站加到搜尋列,方便網友直接找你網站的資訊。
- 2009/1/9 修改XML的Code 讓IE與Firefox都可以正常的新增
demo最近把Firefox搞成3.0 rc2以後晃一些網站都會發現有個奇怪的小圖示如以下幾個網站
在好奇心驅使下,我按下了發現可以直接新增該網站搜尋耶
於是我利用FUNP.COM的原始碼來參考了解了其中奧妙,就想自己也搞一個以下就是教學啦
本篇文章主要是利用google的自訂搜尋來作成自己網站的搜尋引擎,因為demo小鋪就是這樣搞得阿,如果你不知道如何使用Google的自訂搜尋請參考【Custom Search個人化專屬的搜尋引擎】,以下文章假設您已經設定好了Google的搜尋引擎了。
先對你自己的站內搜尋隨便輸入一些字讓它跳到結果頁面,比如小鋪的就如下
-
http://www.google.com.tw/cse?cx=partner-pub-06942224496900484&q=msn
測試時我輸入的是msn所以看得出來該網址的關鍵字是用q做識別,然後我們就要新增一個XML檔案,檔案內容如下
-
<?xml version="1.0" encoding="UTF-8" ?>
-
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
-
<ShortName>demo小鋪</ShortName>
-
<Description>創作、分享、交流的園地~~</Description>
-
<Image width="16" height="16">data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZGxkdhJ6Ew5TClP%2BLuYv%2Fmr2a%2Fz1CPU4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQE5AVZ%2Fxn%2F%2BH0If%2Ff79%2F%2F5C%2BkP9ITUhbAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABodGh6JwYnPlPeU%2F4fTh%2F97l3vGBwcHBwAAAAAA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VFQAAAAAcIBwhjM6M45bdlv9PW09zbaBttZPzk%2F%2BPzI%2F%2Fj7qP%2FzY8Nk8AAAAAAQEBATA9MEJbcVt%2BGhgaGwAAAAAAAAAAAAAAABseGyEnMSc3AgICAjE8MUCR4pH1kO6Q%2F5rKmv87PjtKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMj4yQnGlcbVqhWqdCAcICAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4H8AAOB%2FAADgfwAA8P8AAPgfAADwDwAAwA8AAMAPAADACAAA4AAAAOAAAAAAAAAAABAAAAQ4AAAH%2FwAAh%2F8AAA%3D%3D</Image>
-
<InputEncoding>UTF-8</InputEncoding>
-
<Url type="text/html" template="http://www.google.com.tw/cse?cx=partner-pub-0694222449690045%3Aftc9jjgbn84&">
-
<Param name="q" value="{searchTerms}"/>
-
</Url>
-
</OpenSearchDescription>
以下為您要改的部份
- shortName:改成你網站名字吧
- image:下面在解釋這長長一串是啥鬼
- searchForm:就是把剛剛搜尋結果頁面的q後面字串都幹掉後貼上來就對了(&符號請改用&)
- Url後的template也改的和上面網址一樣
在這裡的圖是使用base64編碼的,所以image是長長的一串,不知道怎麼編碼?很簡單到這網站【圖片轉base64】就好啦,把base64打勾後圖選給它,就會幫你轉好了,然後在整串貼到image裡面
到這裡你的XML就打造好了,我們只要在頁面的head標籤內加上以下兩條宣告即可
-
<link rel="search" type="application/opensearchdescription+xml" title="demoshop" href="demo.xml" />
-
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
- title:表示新增時候的名字(與新增後不一樣...)
- href:為你xml放置的路徑,如果可以就直接丟到根目錄比較穩啦
如果您搜尋錯誤的話就改xml的內容即可,如果無法新增就表示您的head宣告沒打好
回應討論