Javascript page word search JS

Source: Internet
Author: User

Modified based on Jquery. The following are all scripts: Copy codeThe Code is as follows: // search by word
Var GLS = {};
GLS. startObj = null;
GLS. isdb = false;
GLS. allow = true;
GLS. isallow = function (){
If (GLS. allow ){
GLS. allow = false;
Alert ('Google search disabled ');
}
Else {
GLS. allow = true;
Alert ('opened by Google search ');
}
};
GLS. dblclick = function (){
GLS. isdb = true;
};
GLS. mousedown = function (evt ){
Evt = (evt )? Evt: (window. event )? Window. event :"");
If (evt ){
GLS. startObj = (evt.tar get )? Evt.tar get: evt. srcElement;
}
};
GLS. mouseup = function (evt ){
Var obj;
Var strlen;
Evt = (evt )? Evt: (window. event )? Window. event :"");
If (evt ){
Obj = (evt.tar get )? Evt.tar get: evt. srcElement;
Strlen = window. getSelection? Window. getSelection (). toString (): document. selection. createRange (). text;
}
Var str = "";
If (obj. tagName! = "A" & obj. tagName! = "INPUT" & obj = GLS. startObj &&! GLS. isdb & GLS. allow ){
If (strlen. length> 0 ){
Str = strlen;
}
}
GLS. search (str, evt );
GLS. isdb = false;
};
GLS. search = function (str, evt ){
Var obj = $ ("# GLSearch ");
Var sDivWidth = 88; // The width of the search box "Google Search"
If (str. toString (). length> 0 ){
Var implements wwidth; // window width
// Obtain the window width
If (self. innerWidth ){
Required wwidth = self. innerWidth;
} Else if (document.doc umentElement & document.doc umentElement. clientWidth ){
Required wwidth = document.doc umentElement. clientWidth;
} Else if (document. body ){
Required wwidth = document. body. clientWidth;
}
Obj.css ({'display': 'block', 'position': 'absolte', 'zindex': '20140901 '});
Var rX, rX, wT;
If ($. browser. msie ){
WT = (evt. clientX + sDivWidth)-required wwidth;
RY = document.doc umentElement. scrollTop + evt. clientY;
RX = document.doc umentElement. scrollLeft + evt. clientX;
RY = (evt. clientY <25 )? RY + 5: rY-25;
RX = (wT> 0 )? RX-wT: rX + 5;
}
Else {
Var sT = (document.doc umentElement. scrollTop> 0 )? Document.doc umentElement. scrollTop: document. body. scrollTop;
WT = (evt. pageX + sDivWidth)-required wwidth;
RY = (evt. pageY-sT) <25 )? Evt. pageY + 5: evt. pageY-25;
RX = (wT> 0 )? Evt. pageX-wT: evt. pageX + 5;
}
Obj.css ("top", rY );
Obj.css ("left", rX );
Obj.html ("<a class = 'Gl _ s' target = '_ blank' href = 'HTTP: // www.google.com/search? Ie = UTF-8 & oe = UTF-8 & q = "+ encodeURIComponent (str) +" '> Google search </a> ");
}
Else {
Obj.css ("display", "none ");
}
};

// Page loading
$ (Document). ready (function (){
$ (Document. body). append ("<div id = 'glsearch'> </div> ");
$ (Document). mousedown (GLS. mousedown). dblclick (GLS. dblclick). mouseup (GLS. mouseup );
});

Attach CSS/* search */Copy codeThe Code is as follows:. GL_s {width: 68px; height: 20px; display: block; border: solid 1px #2b7ab7; line-height: 20px; padding-left: 18px; color: #084f10; font-size: 12px; font-weight: bold; background: url(search.gif) no-repeat left; text-decoration: none ;}
A. GL_s: link {filter: alpha (opacity = 71);-moz-opacity: 0.7; opacity: 0.7 ;}
A. GL_s: hover {filter: alpha (opacity = 100);-moz-opacity: 1.0; opacity: 1.0 ;}

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.