I think JavaScript is fate for me. But during the course I also have come across some interesting javascript functions. These are such interesting that I could not resist my self from publishing them here. Here goes some of them:

1. Function for opening a popup window:

 function pop_window()
{
var confirmWin = null;
confirmWin = window.open('PopUpWindow.aspx','anycontent',
'width=455,height=435,status');
}
call in html of anyother lang"


2. Previewing image before upload:
unction setImage(file)
{
Thumb = document.getElementById('img1');
Thumb.innerHTML = ''
}
put a p tag with some id say img1.
use a file upload control to upload the image with setImage as callback function.

3. Stop image from copying:
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e)

{

if (document.layers||document.getElementById&&!document.all)

{

if (e.which==2||e.which==3)

{

alert(message);

return false;

}

}

}

if (document.layers)

{
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}

else if (document.all&&!document.getElementById){

document.onmousedown=clickIE4;

}

document.oncontextmenu=new Function(“alert(message);return false”)


or you can use a simple process as well
use oncontextmenu="return false" in body tag.

Note: We all know that one cannot stop people from stealing images from a website, as all the images are first downloaded to the client's computer and then displayed. But still one can pretend to be secure using this function.


4. Function to get current x and y position of mouse(cross browser supported)
function demo(obj){
var posX=0;
var posY=0;
if(typeof(obj.offsetParent) != "undefined"){
for(var x=0, y=0;obj; obj=obj.offsetParent){
x += obj.offsetLeft;
y += obj.offsetTop;
}
posX=x;
posY=y;
}
else{
posX=obj.offsetLeft;
posY=obj.offsetTop;
}
alert("X: "+posX+" Y: "+posY);
}

5. Method to add event to a function (cross borwser support)
function test(event)
{
if(!event)
var event = window.event;
}


I found them interesting. You may also.

Leave a Reply

Your email address will not be published. Required fields are marked *