Posts filed under ‘Javascript’

Insert a character using jquery at some location using substring

Snippet

var count=$(‘.content’).length;
var before=$(‘.content’).text().substring(0,125);
var after=$(‘.content’).text().substring(125,count);
var result=before+’…’+after;

April 8, 2010 at 1:18 pm 1 comment

How to customize addthis plugin

Hey you need not to be PHP expert or javascript expert to customize addthis plugin. Just add this bit of snippet in the <head> tag

<script type=”text/javascript”>
var addthis_config = {
services_compact: ‘facebook, twitter, stumbleupon, digg, orkut, email, more’,
}
</script>

so keep adding rhe social networking sites names with comma separated and you are done.

Enjoy :), hope it helped

March 10, 2010 at 4:18 am Leave a comment

javascript browser detection script

// <![CDATA[
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
var objId=document.getElementById("StageArea");
if ((browser=="Microsoft Internet Explorer") && (version

<script>
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
var objId=document.getElementById(“StageArea”);
if ((browser==”Microsoft Internet Explorer”) && (version<7)) {
if ((screen.width==1024) && (screen.height==768)){

objId.style.height=”472px”;
objId.style.overflow=”visible”;

}
else{
objId.style.height=”725px”;
objId.style.overflow=”visible”;
}

}
else  {
if ((screen.width==1024) && (screen.height==768)){
objId.style.minHeight=”472px”;
}
else{
objId.style.minHeight=”695px”;
}

}

</script>

August 11, 2009 at 7:04 am Leave a comment

iframe change src | javascript

A small snippet for the people who wanna change src of Iframe on click.

Example

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>

<script type=”text/javascript”>
function changeURL(id){
alert(id);
newURL=”http://yahoo.com&#8221;;
document.getElementById(id).src=newURL;
}
</script>

</head>

<body>
<form name=”testForm”>
<iframe id=”test” name=”testName” src=”http://google.com”></iframe&gt;
</form>
<a href=”#” onclick=”changeURL(‘test’);”>dfdfd</a>

</body>
</html>

July 27, 2009 at 3:56 am 7 comments

validating textarea using javascript/dhtml

So many times we need to validate textarea to limit users from entering more charachters

Here is the code which is tested  in IE for validating textarea for 255 charachters.

/*copy this code in head tag */

<script language = “Javascript”>
/**
* Author : suresh kumar
*/

maxL=255;
function taLimit(taObj) {
if (taObj.value.length==maxL) return false;
return true;
}

function taCount(taObj,Cnt) {
objCnt=createObject(Cnt);
objVal=taObj.value;
if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
if (objCnt) objCnt.innerText=maxL-objVal.length;
return true;
}
function createObject(objId) {
if (document.getElementById) return document.getElementById(objId);
else if (document.layers) return eval(“document.” + objId);
else if (document.all) return eval(“document.all.” + objId);
else return eval(“document.” + objId);
}
</script>

/*copy this in body */

<font> Maximum Number of characters for this text box is 255.<br>
<textarea onKeyPress=”return taLimit(this)” onKeyUp=”return taCount(this,’myCounter’)” name=”Description” rows=7 wrap=”physical” cols=40>
</textarea>
<br><br>
You have <B><SPAN id=myCounter>255</SPAN></B> characters remaining
for your description…</font>

March 4, 2008 at 2:45 am 7 comments

Applying background to Iframe [IE / Firefox /Safari / Opera

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>

<style>
#subscribe{
background:#ff0000;

}
</style>
<SCRIPT LANGUAGE=”JavaScript”>
function change_background() {
var iframeDoc;
if (window.frames && window.frames.subscribe && (iframeDoc = window.frames.subscribe.document)) {
// now use iframeDoc here
iframeDoc.body.style.backgroundColor=’red’;
//alert(iframeDoc.body.style.backgroundColor);
}

}
</SCRIPT>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>
</head>

<body onLoad=”change_background();”>
<iframe src=”test1.html” id=”subscribe” name=”subscribe” scrolling=”no” frameborder=”0″></iframe>
</body>

</html>

August 2, 2007 at 3:00 am 3 comments

Arrays / Populating arrays / Sorting in Javascript

<body>
<script language=”javascript”>
myarray=new Array(2);               //A array intialized of size 2
myarray[1]=”suresh”;
myarray[2]=”ganesh”;
for(i=1; i<3; i++)                 //loop goes here
document.write(myarray[i]+”<br>”);
document.write(myarray.sort());         //sorting array elements
</script>
</body>

August 1, 2007 at 5:16 am Leave a comment

Formating / multi formating strings in javascript

<body>

<script language=”JavaScript”>

<!– formating goes here

var myVariable = suresh Theundisputed;

document.write(myVariable.big() + “<br>”);

document.write(myVariable.blink() + “<br>”);

document.write(myVariable.bold() + “<br>”);

document.write(myVariable.fixed() +”<br>”);

document.write(myVariable.fontcolor(red) + “<br>”);

document.write(myVariable.fontsize(12pt) + “<br>”);

</script>

Multi Formatting

<script language=”javascript”>
newvar=”suresh”
bol=newvar.bold().toLowerCase().fontcolor(“red”).italics(); //multiformatting
document.write(bol);

</body>

August 1, 2007 at 4:58 am Leave a comment

Search & Replace in javascript

<body>
<script language=”javascript”>
myvar=”test page”;                     //define a variable
sear=myvar.search(“page”);       //sear is a variable which holds result of search
if(sear==5)                                       // out put will be number
{
document.write(sear);
document.write(“<br>”);
oldvar=”hello there”;
newvar=oldvar.replace(“there”,”suresh”);       //replacing there by suresh
document.write(newvar);                      //output will be “hello suresh”
}
</body>

August 1, 2007 at 4:50 am Leave a comment

Window.open in js when popup is blocked

Hey u guys might be wondering what if js is blocked in a web-browser Use below code to open a new window using javascript when popup is blocked or js is degraded or js is blocked.

/* html code goes here */

<div id=”link”>
<a href=”popup.html” onclick=”fnNewWin(); return false;”>link to popup</a>
</div>

/* js for popup*/

function fnNewWin(){
window.open(‘popup.html’,”,’scrollbars=no’,’resizable=no’,’addressbar=no’ );
}

July 31, 2007 at 11:01 am Leave a comment

Older Posts


Flickr Photos

Jewellery Beach

The Peak

City Alight

More Photos

Blog Stats

  • 626,834 hits

Follow

Get every new post delivered to your Inbox.

Join 35 other followers