This script is modified by code on the Internet and is compatible with mainstream browsers. It optimizes the Search Prompt box location of text loaded asynchronously on the page, and calculates the Search Prompt box Location Based on the selected text location and screen size. Modified based on Jquery. The following are all scripts:
The Code is as follows:
// Word search
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 ("Google Search ");
}
Else {
Obj.css ("display", "none ");
}
};
// Page loading
$ (Document). ready (function (){
$ (Document. body). append ("
");
$ (Document). mousedown (GLS. mousedown). dblclick (GLS. dblclick). mouseup (GLS. mouseup );
});
Attach CSS/* search */
The Code is as follows:
A. 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 ;}