ManyCodes.com – codes & scripts Get free programming codes and tutorials!

28Jul/090

How to have two lines following mouse on your website

Here is how you can have two lines following mouse on your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->
<!-- START OF Mouse Cursor Crosshairs DHTML -->


<!-- SUMMARY BRIEF

 This DHTML script will make a crosshair to follow
 your mouse cursor around.

 You can change the color of the crosshair by changing
 the color hex codes in the <style> tag in the <head>
 of your document.

-->


<!-- Put this portion of the script inside of your <HEAD> tag -->


<style>
<!--

#leftright, #topdown{

 position: absolute;
 left: 0;
 top: 0;
 width: 1px;
 height: 1px;
 layer-background-color: #FF0000;
 background-color: #FF0000;
 z-index: 100;
 font-size: 1px;
}

-->
</style>


<!-- Put this code after your <BODY> tag. -->


<div id="leftright" style="width:expression(document.body.clientWidth-2)"></div>
<div id="topdown" style="height:expression(document.body.clientHeight-2)"></div>

<script language="JavaScript1.2">
<!--

if (document.all&&!window.print){
leftright.style.width=document.body.clientWidth-2
topdown.style.height=document.body.clientHeight-2
}
else if (document.layers){
document.leftright.clip.width=window.innerWidth
document.leftright.clip.height=1
document.topdown.clip.width=1
document.topdown.clip.height=window.innerHeight
}


function followmouse1(){
//move cross engine for IE 4+
leftright.style.pixelTop=document.body.scrollTop+event.clientY+1
topdown.style.pixelTop=document.body.scrollTop
if (event.clientX<document.body.clientWidth-2)
topdown.style.pixelLeft=document.body.scrollLeft+event.clientX+1
else
topdown.style.pixelLeft=document.body.clientWidth-2
}

function followmouse2(e){
//move cross engine for NS 4+
document.leftright.top=e.y+1
document.topdown.top=pageYOffset
document.topdown.left=e.x+1
}

if (document.all)
document.onmousemove=followmouse1
else if (document.layers){
window.captureEvents(Event.MOUSEMOVE)
window.onmousemove=followmouse2
}

function regenerate(){
window.location.reload()
}
function regenerate2(){
setTimeout("window.onresize=regenerate",400)
}
if ((document.all&&!window.print)||document.layers)
//if the user is using IE 4 or NS 4, both NOT IE 5+
window.onload=regenerate2

//-->
</script>


<!-- END OF Mouse Cursor Crosshairs DHTML -->

<font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
28Jul/090

How to allow your website visitor to have the option to save the webpage he is on your website

Here is how you can allow your website visitor to have the option to save the webpage he is on your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->
// IMPORTANT:
// If you add this script to a script-library or a script-archive
// you have to insert a link to http://www.javakhafan.9f.com
// right into the webpage where the script will be displayed.

function doSaveAs(){
 if (document.execCommand){
 document.execCommand("SaveAs")
 }
 else {
 alert("Save-feature available only in Internet Exlorer 5.x.")
 }
}
</script>
<form>
<input type="button" value="Save This WebPage" onClick="doSaveAs()"
</form>

<font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
28Jul/090

How to show today’s Date on your website

Here is how you can show today's Date on your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->

<!-- ONE STEP TO INSTALL MONTHLY:  DAY HIGHLIGHTED:

 1.  Put the code into the BODY of your HTML document  -->
<!-- STEP ONE: Copy this code into the HEAD your HTML document  -->
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>

<body>

<center>
<script LANGUAGE="JavaScript">

<!-- Begin
monthnames = new Array(
"January",
"Februrary",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"Decemeber");
var linkcount=0;
function addlink(month, day, href) {
var entry = new Array(3);
entry[0] = month;
entry[1] = day;
entry[2] = href;
this[linkcount++] = entry;
}
Array.prototype.addlink = addlink;
linkdays = new Array();
monthdays = new Array(12);
monthdays[0]=31;
monthdays[1]=28;
monthdays[2]=31;
monthdays[3]=30;
monthdays[4]=31;
monthdays[5]=30;
monthdays[6]=31;
monthdays[7]=31;
monthdays[8]=30;
monthdays[9]=31;
monthdays[10]=30;
monthdays[11]=31;
todayDate=new Date();
thisday=todayDate.getDay();
thismonth=todayDate.getMonth();
thisdate=todayDate.getDate();
thisyear=todayDate.getYear();
thisyear = thisyear % 100;
thisyear = ((thisyear < 50) ? (2000 + thisyear) : (1900 + thisyear));
if (((thisyear % 4 == 0)
&& !(thisyear % 100 == 0))
||(thisyear % 400 == 0)) monthdays[1]++;
startspaces=thisdate;
while (startspaces > 7) startspaces-=7;
startspaces = thisday - startspaces + 1;
if (startspaces < 0) startspaces+=7;
document.write("<table border=2 bgcolor=white ");
document.write("bordercolor=black><font color=black>");
document.write("<tr><td colspan=7><center><strong>"
+ monthnames[thismonth] + " " + thisyear
+ "</strong></center></font></td></tr>");
document.write("<tr>");
document.write("<td align=center>Su</td>");
document.write("<td align=center>M</td>");
document.write("<td align=center>Tu</td>");
document.write("<td align=center>W</td>");
document.write("<td align=center>Th</td>");
document.write("<td align=center>F</td>");
document.write("<td align=center>Sa</td>");
document.write("</tr>");
document.write("<tr>");
for (s=0;s<startspaces;s++) {
document.write("<td> </td>");
}
count=1;
while (count <= monthdays[thismonth]) {
for (b = startspaces;b<7;b++) {
linktrue=false;
document.write("<td>");
for (c=0;c<linkdays.length;c++) {
if (linkdays != null) {
if ((linkdays[0]==thismonth + 1) && (linkdays[1]==count)) {
document.write("<a href=\"" + linkdays[2] + "\">");
linktrue=true;
 }
 }
}
if (count==thisdate) {
document.write("<font color='FF0000'><strong>");
}
if (count <= monthdays[thismonth]) {
document.write(count);
}
else {
document.write(" ");
}
if (count==thisdate) {
document.write("</strong></font>");
}
if (linktrue)
document.write("</a>");
document.write("</td>");
count++;
}
document.write("</tr>");
document.write("<tr>");
startspaces=0;
}
document.write("</table></p>");
// End -->
</script>
</center>
<!-- Script Size:  2.98 KB  -->

</body>

</html>
<font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
28Jul/090

How to make your website have randomly change its background color

Here is how you can make your website have randomly change its background color.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->
<script>

// Select fade-effect below:
// Set 1 if the background may fade from dark to medium
// Set 2 if the background may fade from light to medium
// Set 3 if the background may fade from very dark to very light light
// Set 4 if the background may fade from light to very light
// Set 5 if the background may fade from dark to very dark
var fade_effect=3

// What type of gradient should be applied Internet Explorer 5x or higher?
// Set "none" or "horizontal" or "vertical"
var gradient_effect="horizontal"

// Speed higher=slower
var speed=60

///////////////////////////////////////////////////////////////////////////
// CONFIGURATION ENDS HERE
///////////////////////////////////////////////////////////////////////////

var browserinfos=navigator.userAgent
var ie4=document.all&&!document.getElementById
var ie5=document.all&&document.getElementById&&!browserinfos.match(/Opera/)
var ns4=document.layers
var ns6=document.getElementById&&!document.all
var opera=browserinfos.match(/Opera/)
var browserok=ie4||ie5||ns4||ns6||opera

if (fade_effect==1) {
 var darkmax=1
 var lightmax=127
}
if (fade_effect==2) {
 var darkmax=127
 var lightmax=254
}
if (fade_effect==3) {
 var darkmax=1
 var lightmax=254
}
if (fade_effect==4) {
 var darkmax=190
 var lightmax=254
}
if (fade_effect==5) {
 var darkmax=1
 var lightmax=80
}
var hexc = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F')

var newred
var newgreen
var newblue
var oldred
var oldgreen
var oldblue

var redcol_1
var redcol_2
var greencol_1
var greencol_2
var bluecol_1
var bluecol_2
var oldcolor
var newcolor
var firsttime=true
 
var stepred=1
var stepgreen=1
var stepblue=1

function setrandomcolor() {
 var range=(lightmax-darkmax)
 if (firsttime) {
 newred=Math.ceil(range*Math.random())+darkmax
 newgreen=Math.ceil(range*Math.random())+darkmax
 newblue=Math.ceil(range*Math.random())+darkmax
 firsttime=false
 }
 
 oldred=Math.ceil(range*Math.random())+darkmax
 oldgreen=Math.ceil(range*Math.random())+darkmax
 oldblue=Math.ceil(range*Math.random())+darkmax
 
 stepred=newred-oldred
 if (oldred>newred) {stepred=1}
 else if (oldred<newred) {stepred=-1}
 else {stepred=0}
 
 stepgreen=newgreen-oldgreen
 if (oldgreen>newgreen) {stepgreen=1}
 else if (oldgreen<newgreen) {stepgreen=-1}
 else {stepgreen=0}
 
 stepblue=newblue-oldblue
 if (oldblue>newblue) {stepblue=1}
 else if (oldblue<newblue) {stepblue=-1}
 else {stepblue=0}
 fadebg()
}

function fadebg() {
 if (newred==oldred) {stepred=0}
 if (newgreen==oldgreen) {stepgreen=0}
 if (newblue==oldblue) {stepblue=0}
 newred+=stepred
 newgreen+=stepgreen
 newblue+=stepblue
 
 if (stepred!=0 || stepgreen!=0 || stepblue!=0) {
 redcol_1 = hexc[Math.floor(newred/16)];
 redcol_2 = hexc[newred%16];
 greencol_1 = hexc[Math.floor(newgreen/16)];
 greencol_2 = hexc[newgreen%16];
 bluecol_1 = hexc[Math.floor(newblue/16)];
 bluecol_2 = hexc[newblue%16];
 newcolor="#"+redcol_1+redcol_2+greencol_1+greencol_2+bluecol_1+bluecol_2
 if (ie5 && gradient_effect!="none") {
 if (gradient_effect=="horizontal") {gradient_effect=1}
 if (gradient_effect=="vertical") {gradient_effect=0}
 greencol_1 = hexc[Math.floor(newred/16)];
 greencol_2 = hexc[newred%16];
 bluecol_1 = hexc[Math.floor(newgreen/16)];
 bluecol_2 = hexc[newgreen%16];
 redcol_1 = hexc[Math.floor(newblue/16)];
 redcol_2 = hexc[newblue%16];
 var newcolorCompl="#"+redcol_1+redcol_2+greencol_1+greencol_2+bluecol_1+bluecol_2
 document.body.style.filter=
"progid:DXImageTransform.Microsoft.Gradient(startColorstr="+newcolorCompl+", endColorstr="+newcolor+" GradientType="+gradient_effect+")"
 }
 else {
 document.bgColor=newcolor
 }
 var timer=setTimeout("fadebg()",speed);
 }
 else {
 clearTimeout(timer)
 newred=oldred
 newgreen=oldgreen
 newblue=oldblue
 oldcolor=newcolor
 setrandomcolor()
 }
}

if (browserok) {
 window.onload=setrandomcolor
}
</script>

<font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
28Jul/090

How to show how many visitors are online on your website

Here is how you can show how many visitors are online on your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<pre><!-- this script is from www.manycodes.com --></pre>
<script src=http://fastonlineusers.com/online.php?d=www.mohager.co.sr></script>

<font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
28Jul/090

How to put a calculator script on your website

Here is how you can put a calculator script on your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->
<!-- A Simple Calculator -->
<!-- Instructions: Just put this script anywhere on your webpage
 between the body tags and you will have a calculator for your visitors!  -->
<!-- Script supplied with CoffeeCup HTML Editor -->
<!--             www.coffeecup.com              -->
<CENTER>

<FORM name="Keypad" action="">
<TABLE>
<B>
<TABLE border=2 width=50 height=60 cellpadding=1 cellspacing=5>
<TR>
<TD colspan=3 align=middle>
<input name="ReadOut" type="Text" size=24 value="0" width=100%>
</TD>
<TD
</TD>
<TD>
<input name="btnClear" type="Button" value="  C  " onclick="Clear()">
</TD>
<TD><input name="btnClearEntry" type="Button" value="  CE " onclick="ClearEntry()">
</TD>
</TR>
<TR>
<TD>
<input name="btnSeven" type="Button" value="  7  " onclick="NumPressed(7)">
</TD>
<TD>
<input name="btnEight" type="Button" value="  8  " onclick="NumPressed(8)">
</TD>
<TD>
<input name="btnNine" type="Button" value="  9  " onclick="NumPressed(9)">
</TD>
<TD>
</TD>
<TD>
<input name="btnNeg" type="Button" value=" +/- " onclick="Neg()">
</TD>
<TD>
<input name="btnPercent" type="Button" value="  % " onclick="Percent()">
</TD>
</TR>
<TR>
<TD>
<input name="btnFour" type="Button" value="  4  " onclick="NumPressed(4)">
</TD>
<TD>
<input name="btnFive" type="Button" value="  5  " onclick="NumPressed(5)">
</TD>
<TD>
<input name="btnSix" type="Button" value="  6  " onclick="NumPressed(6)">
</TD>
<TD>
</TD>
<TD align=middle><input name="btnPlus" type="Button" value="  +  " onclick="Operation('+')">
</TD>
<TD align=middle><input name="btnMinus" type="Button" value="   -   " onclick="Operation('-')">
</TD>
</TR>
<TR>
<TD>
<input name="btnOne" type="Button" value="  1  " onclick="NumPressed(1)">
</TD>
<TD>
<input name="btnTwo" type="Button" value="  2  " onclick="NumPressed(2)">
</TD>
<TD>
<input name="btnThree" type="Button" value="  3  " onclick="NumPressed(3)">
</TD>
<TD>
</TD>
<TD align=middle><input name="btnMultiply" type="Button" value="  *  " onclick="Operation('*')">
</TD>
<TD align=middle><input name="btnDivide" type="Button" value="   /   " onclick="Operation('/')">
</TD>
</TR>
<TR>
<TD>
<input name="btnZero" type="Button" value="  0  " onclick="NumPressed(0)">
</TD>
<TD>
<input name="btnDecimal" type="Button" value="   .  " onclick="Decimal()">
</TD>
<TD colspan=3>
</TD>
<TD>
<input name="btnEquals" type="Button" value="  =  " onclick="Operation('=')">
</TD>
</TR>
</TABLE>
</TABLE>
</B>
</FORM>
</CENTER>
<font face="Verdana, Arial, Helvetica" size=2>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var FKeyPad = document.Keypad;
var Accumulate = 0;
var FlagNewNum = false;
var PendingOp = "";
function NumPressed (Num) {
if (FlagNewNum) {
FKeyPad.ReadOut.value  = Num;
FlagNewNum = false;
 }
else {
if (FKeyPad.ReadOut.value == "0")
FKeyPad.ReadOut.value = Num;
else
FKeyPad.ReadOut.value += Num;
 }
}
function Operation (Op) {
var Readout = FKeyPad.ReadOut.value;
if (FlagNewNum && PendingOp != "=");
else
{
FlagNewNum = true;
if ( '+' == PendingOp )
Accumulate += parseFloat(Readout);
else if ( '-' == PendingOp )
Accumulate -= parseFloat(Readout);
else if ( '/' == PendingOp )
Accumulate /= parseFloat(Readout);
else if ( '*' == PendingOp )
Accumulate *= parseFloat(Readout);
else
Accumulate = parseFloat(Readout);
FKeyPad.ReadOut.value = Accumulate;
PendingOp = Op;
 }
}
function Decimal () {
var curReadOut = FKeyPad.ReadOut.value;
if (FlagNewNum) {
curReadOut = "0.";
FlagNewNum = false;
 }
else
{
if (curReadOut.indexOf(".") == -1)
curReadOut += ".";
 }
FKeyPad.ReadOut.value = curReadOut;
}
function ClearEntry () {
FKeyPad.ReadOut.value = "0";
FlagNewNum = true;
}
function Clear () {
Accumulate = 0;
PendingOp = "";
ClearEntry();
}
function Neg () {
FKeyPad.ReadOut.value = parseFloat(FKeyPad.ReadOut.value) * -1;
}
function Percent () {
FKeyPad.ReadOut.value = (parseFloat(FKeyPad.ReadOut.value) / 100) * parseFloat(Accumulate);
}
// End -->
</SCRIPT>
<pre><font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font></pre>
28Jul/090

How to put a print button on your website

Here is how you can put a print button on your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- Print Page Script
Use this script to have your
users print your HTML page
-->
<SCRIPT LANGUAGE="JavaScript">
if (window.print) {
document.write('<form> '
+ '<input type=button name=print value="Click" '
+ 'onClick="javascript:window.print()"> To Print this page!</form>');
}
// End -->
</script>
<font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
28Jul/090

How to put a back and forward button on your website

Here is how you can put a back and forward button on your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->
<!-- Start of Back/Forward Buttons Script-->
<!-- Instructions: Just put this script anywhere on your webpage
 and you will give your visitor 2 Back and Forward Navigation
 buttons.  Designed for websites that have multiple webpages.
-->
<SCRIPT LANGUAGE="JavaScript">
<!-- hide this script tag's contents from old browsers
function goHist(a)
{
 history.go(a);      // Go back one.
}
//<!-- done hiding from old browsers -->
</script>
<FORM METHOD="post">
<INPUT TYPE="button" VALUE="  BACK " onClick="goHist(-1)">
<INPUT TYPE="button" VALUE="FORWARD" onClick="goHist(1)">
</form>

<!-- End of Back/Forward Buttons Script -->

<font face="Tahoma"><a target="_blank" href="http://www.javascriptfreecode.com/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font></textarea>
<br>
<input style="CURSOR: hand" id="copy" onclick="highlight('copypaste');" value="Highlight &amp; copy to clipboard" style="border: 1px solid rgb(206, 44, 13); color: rgb(206, 44, 13); font-family: Tahoma; font-size: 8pt; background-color: rgb(227, 229, 231);" type="button"></p>
 <p>

 <a href="index.htm">
 <img border="0" src="images/home2.gif" width="17" height="17">
 Back to main page</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 <a href="contactus.htm">
 <img border="0" src="images/icon_friends_20x20.gif" width="20" height="20">Contact
 us for any questions or comments</a></p>
 </form>
 </td>
 </tr>
 <tr>
 <td height="42" align="left" valign="top">
 <p align="center">The code is active (<b>Sample Code</b>):
 you can see it in the area below or on the page</td>

 </tr>
 </table>
 <p align="center">

<!-- Start of Back/Forward Buttons Script-->
<!-- Instructions: Just put this script anywhere on your webpage
 and you will give your visitor 2 Back and Forward Navigation
 buttons.  Designed for websites that have multiple webpages.
-->
<SCRIPT LANGUAGE="JavaScript">
<!-- hide this script tag's contents from old browsers
function goHist(a)
{
 history.go(a);      // Go back one.
}
//<!-- done hiding from old browsers -->
</script>
<FORM METHOD="post">
<INPUT TYPE="button" VALUE="  BACK " onClick="goHist(-1)">
<INPUT TYPE="button" VALUE="FORWARD" onClick="goHist(1)">
</form>

<!-- End of Back/Forward Buttons Script -->
<pre><font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
</pre>
</td>
 <td width="4" align="left" valign="top"> </td>
 </tr>
 </table></td>
 </tr>
 <tr>
 <td><img src="images/trans.gif" width="10" height="10"></td>
 </tr>
 <tr>
 <td height="32" background="images/bottom_bg.gif">
 <a name="©">©</a> 2006. All rights reserved, Designed by:
 <a href="http://www.manycodes.com/"><span style="text-decoration: none">
free codes</span></a></td>
 </tr>
 </table></td>
 </tr>
</table>
</body>
</html>
<pre><font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font></pre>
28Jul/090

How to shake internet explorer window from your website

Here is how you can shake internet explorer window from your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->

<!-- START CODE Powered javascript code by WWW.javakhafan.7p.COM-->

<meta http-equiv="Content-Language" content="en-us">
<SCRIPT language=JavaScript>
<!-- Begin
function shake(n) {
if (parent.moveBy) {
for (i = 10; i > 0; i--) {
for (j = n; j > 0; j--) {

parent.moveBy(-i,0);
parent.moveBy(0,-i);
parent.moveBy(-i,0);
parent.moveBy(0,i);
parent.moveBy(i,0);
parent.moveBy(0,-i);
parent.moveBy(-i,0);
parent.moveBy(0,i);
parent.moveBy(i,0);
parent.moveBy(0,-i);
parent.moveBy(-i,0);
parent.moveBy(0,-i);
parent.moveBy(i,0);
parent.moveBy(0,i);
parent.moveBy(i,0);
parent.moveBy(0,i);
 }
 }
 }

}
//  End -->

<!--
shake(1);
//-->
 </SCRIPT>
<pre><font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font></pre>
28Jul/090

How to put a text following mouse on your website

Here is how you can put a text following mouse on your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->
<!-- START OF Mouse Cursor Text Trailer DHTML -->

<!-- SUMMARY BRIEF

 This DHTML script will make a text message follow
 your cursor around the screen. You can change the
 message to say whatever you want.

 You can change the font face, color and size in
 the .trailersytle tag below. You can change the message
 in the javascript below that. Just look for the
 comment that says "Insert your personal message below."

-->

<!-- Put this portion of the script inside of your <HEAD> tag -->

<style>
.trailerstyle {
 position: absolute;
 visibility: visible;
 top: -50px;
 font-size: 12px;
 font-family: Arial,Helvetica,Verdana;
 font-weight: bold;
 color: #000000;
}
</style>

<script>
<!--

var x,y
var step=20
var flag=0

// Insert your personal message below.
// Important: Do NOT remove the space at the end of the sentence!!!

var message=" www.javascriptfreecode.com "
message=message.split("")

var xpos=new Array()
for (i=0;i<=message.length-1;i++) {
 xpos[i]=-50
}

var ypos=new Array()
for (i=0;i<=message.length-1;i++) {
 ypos[i]=-50
}

function handlerMM(e){
 x = (document.layers) ? e.pageX : document.body.scrollLeft+event.clientX
 y = (document.layers) ? e.pageY : document.body.scrollTop+event.clientY
 flag=1
}

function mousetrailer() {
 if (flag==1 && document.all) {
 for (i=message.length-1; i>=1; i--) {
 xpos[i]=xpos[i-1]+step
 ypos[i]=ypos[i-1]
 }
 xpos[0]=x+step
 ypos[0]=y

 for (i=0; i<message.length-1; i++) {
 var thisspan = eval("span"+(i)+".style")
 thisspan.posLeft=xpos[i]
 thisspan.posTop=ypos[i]
 }
 }

 else if (flag==1 && document.layers) {
 for (i=message.length-1; i>=1; i--) {
 xpos[i]=xpos[i-1]+step
 ypos[i]=ypos[i-1]
 }
 xpos[0]=x+step
 ypos[0]=y

 for (i=0; i<message.length-1; i++) {
 var thisspan = eval("document.span"+i)
 thisspan.left=xpos[i]
 thisspan.top=ypos[i]
 }
 }
 var timer=setTimeout("mousetrailer()",30)
}

//-->
</script>

<!-- Put this code inside of your <BODY> tag. -->

<script>
<!--

for (i=0;i<=message.length-1;i++) {
 document.write("<span id='span"+i+"' class='trailerstyle'>")
 document.write(message[i])
 document.write("</span>")
}

if (document.layers){
 document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;

//-->
</script>

<!-- Lastly, insert the following into the <BODY> tag, itself, just like the example that follows. -->

<body onLoad="mousetrailer()" style="width:100%;overflow-x:hidden;overflow-y:scroll">

<!-- END OF Mouse Cursor Text Trailer DHTML -->
<pre><font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font></pre>
Tagged as: , , No Comments