Archive for July, 2005

How to Disable the browsers’ back button

You can Disable the browsers’ back button if you want to prevent your users to go back for some reasons like the registration page or for some pages once they are submitted should not be reversed back, which might lead into unwanted problems .

There is a little hack to achieve this, you can use the following js code.


location.replace(yourURL)
window.history.forward(1);

Close Window in IE from javascript. (Small Hack)

When trying to close an window from javascript in IE, which is opened manually,
a security warning “The web page you are viewing is trying to close the window. Do you want to close this window? Yes|No ” is popping up. Is there any possibility to close a window silently? Yes.

A simple hack i found on the web will help to get rid of this situation.


this.focus();
self.opener = this;
self.close();

but in Firefox you can do this. Firefox will not allow you to close using the above code. Maybe anybody found/having any code post it here.

How to find your Popup is blocked by Popup blocker in javascript

How to find your Popup is blocked by Popup blocker in javascript when using window.open.

We open a window using window.open() in our pages using javascript. But if there is popup blocker sitting in the client machine and the user is not aware the popup blocker is blocking the popup window from your site, we can inform him the popup is blocked and ask him to remove that. How?


winHandle=window.open('yourfile.htm' + "?newwin=true", "_top", "width="+wwidth+",height="+wheight+",location=0,menubar=0,resizable=no,scrollbars=no,status=yes,titlebar=no,dependent=yes");
if(winHandle==null){
alert("Error: While Launching New Window...nYour browser maybe blocking up Popup windows. nn  Please check your Popup Blocker Settings");
}

How to Change an image’s width dynamically from Javascript

How to Change an image’s width dynamically from Javascript. Using DOM we can do this.

function changeImgSize(objectId,newWidth,newHeight) {
imgString = 'theImg = document.getElementById("'+objectId+'")';
eval(imgString);
oldWidth = theImg.width;
oldHeight = theImg.height;
if(newWidth>0){
theImg.width = newWidth;
}
if(newHeight>0){
theImg.height = newHeight;
}
}

Note: this one i found on the web but i can’t remember where i found. Credits to the author.

Check whether an HTML element/Object exists or not.

This small javascript function will help you to check if a HTML object.Element exists in a page from the page itself or from a popup window.


function chkObject(inParent,theVal) {
if(inParent){
if (window.opener.document.getElementById(theVal) != null) {
return true;
} else {
return false;
}
}else{
if (document.getElementById(theVal) != null) {
return true;
} else {
return false;
}
}
}

Note:
chks whether an object exists or not in the document.
if the inParent is true then the object/elt is checked for its existence in the parent/opener’s document.
i.e., it will be useful to chk from a popup window.
To check in the current document itself , then set inParent value as false.

Feedback Form