Archive

Archive for the ‘JavaScript’ Category

How to detect the javascript is enable or disable?

Hi friends,

if the one site most of functionality in javascript, if the browser is disable the javascript, then total site will not working, to detect the that the javascript is disable or not, to that following code will work:

<noscript>
    Javascript is disable, please enable to access the site.
</noscript>

Categories: JavaScript

Simple tooltip using javascript and css?

The following code will generate the simple tooltip using Javascript and css.

The Javascript code :

<script language=”javascript” type=”text/javascript”>
/* This tooltip library was created by Anil Kumar  */
function showtip(e,message)

{var x=0;

var y=0;

var m;

var h;

if(!e)
var e=window.event;

if(e.pageX||e.pageY) { x=e.pageX;  y=e.pageY;  }

else if(e.clientX||e.clientY)

{ x=e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;y=e.clientY+document.body.scrollTop+document.documentElement.scrollTop;}
m=document.getElementById(‘mktipmsg’);

if((y>10)&&(y<450))

{  m.style.top=y-4+”px”;  }

else{  m.style.top=y+4+”px”;  }

var messageHeigth=(message.length/20)*10+25;

if((e.clientY+messageHeigth)>510)

{  m.style.top=y-messageHeigth+”px”; }
if(x<850) { m.style.left=x+20+”px”;  }

else{  m.style.left=x-170+”px”;  }

m.innerHTML=message;m.style.display=”block”;m.style.zIndex=203;

}

function hidetip(){

var m;

m=document.getElementById(‘mktipmsg’);m.style.display=”none”;

}

</script>

The CSS Code:

<style type=”text/css”>

#mktipmsg {padding: 5px; background-color: #FFF8DC;  border: 1px solid #DEB887; width:180px;font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #6b6b6b; display:none; position:absolute;left:0px;top:0px; }
</style>

The html Code :

<a href=”javascript:void(0)” onmouseover=”showtip(event, ‘Simple tooltip text’);”
onmouseout=”hidetip();”>Hover your mouse here to see simple tooltip text.</a><br>

<div id=”mktipmsg” ></div>

It will be useful …

Categories: JavaScript

To disable the right click on the webpage?

Hi friends,

After working hard to complete your  design and images  ,some persons just save that images and web pages.

This is one  idea to disable the right click on webpage.

just put a small javascript code at the place between the head section.

*************************

<SCRIPT LANGUAGE=”JavaScript”>
<!– Disable
function disableselect(e){
return false
}

function reEnable(){
return true
}

//if IE4+
document.onselectstart=new Function (“return false”)
document.oncontextmenu=new Function (“return false”)
//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
//–>
</script>

*****************************

Categories: JavaScript

To count the characters in a textarea

Hi frineds ,

This is a simple script but we are using sometimes.

In the header section of the page:

**********************************

<!– Start the Script  –>
<script language=javascript>
//Edit the counter/limiter value as your wish
var count = “125″;   //Example: var count = “143″;
function limiter(){
var tex = document.myform.comment.value;
var len = tex.length;
if(len > count){
tex = tex.substring(0,count);
document.myform.comment.value =tex;
return false;
}
document.myform.limit.value = count-len;
}

</script>
<!– end of Script  –>

************************************

In the body section put the below code :

************************************

<!– Script  –>
<form name=”myform” METHOD=”POST”>
<table  style=”border: #CCFF99 5px solid” >
<tr>
<td>
<textarea name=comment wrap=physical rows=3 cols=40 onkeyup=limiter() style=”border:#CCFF66 1px solid”></textarea></td>
</tr>
<tr><td align=”right”>Character left:
<script language=javascript>
document.write(“<input type=text name=limit size=4 readonly value=”+count+”>”);
</script>
</td></tr></table>
</form>
<!– Script  –>

**************************************

counter

Hope that it is useful.

Categories: JavaScript