<html>
<head>
<style type="text/css">
<!--
p { color: blue; font-size: 37px; font-family: impact }
-->
</style>
<title>Screen and Mouse position</title>
</head>
<script language="javascript">
var titlePopup=window.createPopup();
var content;
var tID;
var time=1000;
var yOffset;
var xOffset;
var width;
var height;
/*
* This fuction InitMsBox(content) is used to initialize the message-box, whose variable conten is a array need your input as "['messag1', 'message2', ...]" ,
* When you need dividing the different message, you can use comma to divide them,or you can input '<br/>' to break the line.
* If you want to change the message-box's color, border or orthers, you can rewrite the inner variable of "table" writed in this function.
*/
function InitMsgBox(content)
{
var str=content[0];
var nbr=KMP(str);
content=new Array(nbr);
content[0]=str;
for(t=1;t<nbr;t++)
{
content[t]=" ";
}
var titlePopupBody = titlePopup.document.body;
titlePopupBody.style.border ="solid black 1px";
var titleContent = "";
titleContent = titleContent + "<table cellPadding='5' bgcolor='#65c1ff' width='100%' height='100%' border=0 cellspacing=0 cellpadding=0>";
width=getLength(content[0]);
// alert("original length "+content[0].length);
// alert("cuted length "+width);
for(i=0;i<content.length;i++)
{
titleContent = titleContent + "<tr><td><font size = 2>"+content[i]+"</font></td></tr>";
if(getLength(content[i])>width)
{
width=getLength(content[i]);
}
}
titleContent = titleContent + "</table>";
titlePopupBody.innerHTML = titleContent;
xOffset=window.event.x;
yOffset=window.event.y;
height=content.length*32;
width=width*9;
ShowMsgBox(xOffset,yOffset,time);
}
/*
* This function ShowMsgBox(xOffset,yOffset,time) is used to show the message-box on screen, whose
* variable xOffset and yOffset are used to set the position on screen, and the variabel time is used to set the time of reflection.
*/
function ShowMsgBox(xOffset,yOffset,time)
{
tID = window.setTimeout("MsgBox(xOffset, yOffset)",time);
}
function MsgBox(xOffset, yOffset)
{
if (window.closed)
{
window.clearInterval(tID);
}
else
{
if(xOffset<document.body.clientWidth-width)
{
if(yOffset<document.body.clientHeight-height)
{
titlePopup.show(xOffset, yOffset+20, width, height, top.document.body);
}
else
{
titlePopup.show(xOffset, yOffset-height-20, width, height, top.document.body);
}
}
else
{ if(yOffset<document.body.clientHeight-height)
{
titlePopup.show(xOffset-width, yOffset+20, width, height, top.document.body);
}
else
{
titlePopup.show(xOffset-width, yOffset-height-20, width, height, top.document.body);
}
}
}
}
/*
* This fuctin load is used to initialaze the application.
*/
function load()
{
var ele =document.getElementsByName("tip");
var tipsArray=new Array();
var contentItem;
for(var i=0;i<ele.length;i++)
{
contentItem=KMP(ele[i].titletips);
ele[i].onmouseover =function() {InitMsgBox([this.titletips])};
ele[i].οnmοuseοut=function() {titlePopup.hide();}
}
}
/*
*This fuction was writen by D.E.Knuth,J.H.Morris和V.R.Pratt,
*I just rewrited some of the codes.
*/
function KMP(tip)
{
var br="<br/>";
var i=0; var j=0; var c=0;
while(i<tip.length && j<br.length)
{
if(tip.substr(i,1)==br.substr(j,1))
{
++i;
++j;
if(j==br.length)
{
c++;
j=0;
}
}
else{i=i-j+1;j=0}
}
return c+1;
}
/*
* This fuction can return the length of item in the table
*/
function getLength(ostr)
{
var length=0;
str=ostr.replace(/<br//>/g,'//');
str=str.replace(/<b>/g,"");
str=str.replace(/<//b>/g,"");
var temp=0;
for(i=0;i<str.length;i++)
{
if(str.substr(i,1)=='//')
{
temp=i-temp;
if(temp>length){length=temp;}
}
}
if(length==0){length=str.length;}
return length;
}
</script>
<body οnlοad="load()" >
<p><input id="Button1" style="left: 122px; position: absolute; top: 172px" type="button"
value="button" name="tip" titletips="James Bond"/></p>
<p><a id="link" href="http://127.0.0.1" name="tip" titletips="My name is<br/>Bond,<b>James Bond</b>" >Lost</a></p>
</body>
</html>