Sogou "Cloud" input method, implementation principle.

Source: Internet
Author: User

Recently, sogou launched the so-called cloud input method (http://pinyin.sogou.com/cloud)

Sogou's online input method is just a little tricky. It is also called "Cloud ".
The implementation method is simple. Let your browser execute a Javascript script.

Javascript: Void (( Function (){ VaR % 20n = Navigator. useragent. tolowercase (); IE = N. indexof ( ' MSIE ' ) ! =- 1 ? 1 : 0 ; If (Document.doc umentmode) IE = 0 ; Charset = '' ; If (IE) charset = Document. charset; SRC = IE && Charset = ' UTF-8 ' ? ' Http://web.pinyin.sogou.com/web_ime/init2_utf8.php ' : ' Http://web.pinyin.sogou.com/web_ime/init2.php ' ; Element = Document. createelement ( ' Script ' ); Element. setattribute ( ' SRC ' , Src); document. Body. appendchild (element );})())

After executing this section of JS, the current web page you browse will appear. The so-called "Cloud" input method is displayed.
In fact, a script tag is dynamically generated from the current page body through Js. the src attribute of the script tag is the address of the page to be called. A script element is generated after initialization. then, I used Ajax technology to interact with the server. in this way, you can input a letter, and then return the Chinese characters from the server to give you a selection.

We canCodeFor use.

 

  < Script Type = " Text/JavaScript " >
Function Hooyesdoit (){
VaR N = Navigator. useragent. tolowercase ();
IE = N. indexof ( ' MSIE ' ) ! =- 1 ? 1 : 0 ;
If (Document.doc umentmode) IE = 0 ; Charset = '' ;
If (IE) charset = Document. charset;
SRC = IE && Charset = ' UTF-8 ' ? ' Http://web.pinyin.sogou.com/web_ime/init2_utf8.php ' : ' Http://web.pinyin.sogou.com/web_ime/init2.php ' ;
Element = Document. createelement ( ' Script ' );
Element. setattribute ( ' SRC ' , Src );
Document. Body. appendchild (element );}
< / SCRIPT>

 

Compile a js method and call it with a button.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.