Monday, November 24, 2008

JavaScript Tutorials Part-III

  • Script for Closing window if opened Independently:


window.onload=function()

{

if(!window.opener)

window.close();

}


  • Script for Clear Authentication Cookie:

function _spBosyOnLoad()

{

try

{

document.execCommand(“ClearAuthenticationCache”);

window.close();

}

catch(e){}

}

JavaScript Tutorials Part-II

  • Script for watercolor logo:


<script language="JavaScript1.2">

if (document.all||document.getElementById)

document.body.style.background="url('logo1.jpg') white center no-repeat fixed"

script>

With in the body tag code.

  • Script for Domain Info:


<script type="text/javascript">

document.write(document.domain+'
'
);

document.write(document.referrer +'
'
);

document.write(document.URL +'
'
);

document.write("This document contains: " + document.forms.length + " forms."+'
'
);

document.write("This document contains: " + document.images.length + " images."+'
'
);

document.write("This document contains: " +document.anchors.length+ " anchors."+'
'
);

document.write(document.title);

script>

  • Script for Say about mouse click:


<body onmousedown="whichButton(event);">

<script type="text/javascript">

function whichButton(event)

{

if (event.button==2)

{

alert("You clicked the right mouse button!");

}

else

{

alert("You clicked the left mouse button!");

}

}

script>

  • Script for Ctrl+C:


<script language="javascript" type="text/javascript">

function onKeyDown() {

// current pressed key

var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();

if ((event.ctrlKey && (pressedKey == "c")) )

{ // disable key press porcessing

event.returnValue = false;

}

} // onKeyDown

script>


  • Script for Disable Right Click:


<script language="javascript" type="text/javascript">

document.onmousedown=disableclick;

status="Right Click Disabled";

function disableclick(e)

{

if(event.button==2)

{

alert(status);

return false;

}

}

script>


  • Script for Disable Selection in WEB Page:


<body onkeydown="onKeyDown()" oncontextmenu="return false" ondragstart="return false" onselectstart="return false">


  • Script for BookMark:


function addBookmark(title, url) {

if (window.sidebar) { // firefox

window.sidebar.addPanel(title, url,"");

}

else if( document.all ) { //MSIE

window.external.AddFavorite( url, title);

}

else {

alert("Sorry, your browser doesn't support this");

}

}

JavaScript Tutorials

HTML clipboardHTML clipboard
  • Script for No Enter Action:
JavaScript function for No Action when enter button is pressed in the page.

function noenter()
{
var key;
if(window.event)
key = window.event.keyCode; //IE
return (key!= 13); //13 ASCII code
}

the page_load event call this method as:

this.Form.Attributes.Add("onkeypress", "return noenter()");

  • Script for Browser Back Disable & Browser Back:
<scripttype ="text/javascript">
javascript:window.history.forward(1);<script>

javascript:history.back(1)and also for Browser back.

  • Script for Right Click Disable:
<body onContextmenu = "alert('Right Click not Allowed!');return false;">

  • Script for alert message while closing (Unloading) the Page:
<body onbeforeunload="alert('You are about to close the window');">