Baidu to the webmaster open free "Baidu search box" code and "Baidu search box hint" code. Simply set up, you can quickly add the "Baidu search box (with prompt function)" function to your Web page. Enhance the user's search experience in the site.
According to the different types of Web site requirements, webmaster tools to provide a total of three types of introduction for you to choose:
Simple way-Convenient to add the "Baidu search box (with prompt function)" directly into your Web page. Add the following code to your webpage to get the Baidu search box with the "search box hint" function
HTML code:
<form action= "Http://www.baidu.com/baidu" target= "_blank" >
<table bgcolor= "#FFFFFF" ><tr><td>
<input name= "tn" type= "hidden" value= "Baidu" >
<a href= "http://www.baidu.com/" ></a>
<input type= "text" name= "word" size= "30″baidusug=" 1″>
<input type= "Submit" value= "Baidu Search" >
</td></tr></table>
</form>
JavaScript code:
<script charset= "GBK" src= "Http://www.baidu.com/js/opensug.js" ></script>
Tips: JavaScript code to be added to the page </body> tag after the use of UTF-8 encoding, you need to add <input name= "ie" type= "hidden" in the HTML code value= "UTF-8″> Also be sure to set the CHARSET=GBK attribute in the script tag, otherwise the search keyword and hint Word will appear garbled.
View Sample Effects
Add a way-quickly for the page already have "Baidu search box" or other text input box added "Baidu Search box hint" function.
The first step
Add the Baidusug attribute to the <input> tag that needs to add the "Baidu Search box hint" feature. For example:
<input type= "text" name= "word" baidusug= "1|2″>
When the baidusug=1 is set, the user selects the SUG entry by default to execute the form submission action;
When baidusug=2 is set, the user does not perform a form submission action when the SUG entry is selected.
Step Two
Introduce JavaScript files into your Web page:
<script charset= "GBK" src= "Http://www.baidu.com/js/opensug.js" ></script>
Tip: If you have more than one input box in your Web page that requires the "Baidu search box hint" feature, add the Baidusug attribute to each input box. JavaScript code is added to the Web page after the </body> tag. If you use UTF-8 encoding, be sure to set the CHARSET=GBK property in the Script tab, otherwise the search hint Word will be garbled.
View Sample Effects
Advanced Way-Provide "Baidu search box hint" API to create your personalized search box prompt Function!
The first step
Introduce JavaScript files into your Web page:
<script charset= "GBK" src= "Http://www.baidu.com/js/opensug.js" ></script>
Step Two
Calling the Baidusuggestion.bind () method in a JavaScript program binds the "Baidu Search box hint" feature to the elements on the page.
The specific form of Baidusuggestion.bind () is:
Baidusuggestion.bind (Inputobj|inputid,[params],[confirmcallback]); Inputobj|inputid:
Is the ID of the input object or input object that needs to be bound to the search box hint function.
Params:
The parameters used to bind the search box hint function must be given in JSON form, for example:
{"Xoffset": 0,//Tip box Position horizontal offset, unit px "Yoffset": 0,//Tip box Position vertical offset, unit px "width": 350,//Hint box width, unit px "fontcolor": "#03c",// Hint box text color "Fontcolorhi": "#FFF",///Cue box Highlight selection text color "fontSize": "12px",//Text Size "fontFamily": "Arial",//Text font "bordercolor": "#03c" ,///The border color of the cue box "Bgcolorhi": "#fd0",///Cue box highlight the selected color "Sugsubmit": false///Select whether to submit the form when the entry in the Prompt box}
Confirmcallback (TXT):
When the user chooses the prompt in the specific option of the callback function, TXT for the user to select the content.
Tip: If you have more than one input box in your Web page that requires the "Baidu search box hint" feature, add the Baidusug attribute to each input box. JavaScript code is added to the Web page after the </body> tag. If you use UTF-8 encoding, be sure to set the CHARSET=GBK property in the Script tab, otherwise the search hint Word will be garbled.
Webmaster Tools | Baidu Search box prompt function