Functions find Left and Right position of an Object

When a layer is inside another layer, it’s style.left and style.top positions can both be ‘0’
but the layer itself can be 500 pixels away from the actual margin. These functions will return
the true offset.
// To find the left position, add this snippet to your code:

function getPositionLeft(This){
var el = This;var pL = 0;
while(el){pL+=el.offsetLeft;el=el.offsetParent;}
return pL
}

// To find the top position, add this snippet to your code:

function getPositionTop(This){
var el = This;var pT = 0;
while(el){pT+=el.offsetTop;el=el.offsetParent;}
return pT
}

Get all Indexes of Duplicate Entries in an array

Array.prototype.collectDuplicateIndices = function (value)
// Returns true if the passed value is found in the
// array. Returns false if it is not.

{
var i;
var dupesStr = “”;
for (i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i] == value) { dupesStr += i+","; } } return (dupesStr>“”)?dupesStr:”null”;
};

This will return all the index/positions of the duplicate entries in an Array as a string seperated with commas.

For example the Returned string will be 1,77,55
Where 1,77 and 55 are the positions of the duplicate entries in the array. ( Or you can say those positions are having the duplicate entries)

Check if an element or value exists in an array or not

This function will Check if an element or value exists in an array or not.
And return true if the passed value is found in the array. Returns false if it is not found in the array.

Array.prototype.inArray = function (value,caseSensitive)
// Returns true if the passed value is found in the
// array. Returns false if it is not.
{
var i;
for (i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), if(caseSensitive){ //performs match even the string is case sensitive if (this[i].toLowerCase() == value.toLowerCase()) { return true; } }else{ if (this[i] == value) { return true; } } } return false; }; Note : If you don't want to perform case sensitive check, then set caseSensitve=true and call the function.

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");
}

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.

To load an doc inside a iframe dynamically

We can load a document into an iframe dynamically by using iframe.src = “yourpage” in javascript.
But this works well in IE and not in others browsers. Here is an method to load iframes dynamically.

I found this at http://developer.apple.com/internet/webcontent/iframe.html and just changed something to fit our need.


var IFrameObj;
function loadIFrame(thePage){
//loads an doc inside a iframe dynamically
URL = thePage;
IFrameObj = new Object();
IFrameObj.document = new Object();
IFrameObj.document.location = new Object();
IFrameObj.document.location.iframe = document.getElementById('cpaneif');
IFrameObj.document.location.replace = function(location) {
this.iframe.src = location;
}

if (navigator.userAgent.indexOf(‘Gecko’) !=-1 && !IFrameObj.contentDocument) {
// allow a fraction of a second to recognize the new IFrame
//setTimeout(‘loadIFrame(“‘+thePage+'”)’,10);
//return false;
}

if (IFrameObj.contentDocument) {
// For NS6
IFrameDoc = IFrameObj.contentDocument;
} else if (IFrameObj.contentWindow) {
// For IE5.5 and IE6
IFrameDoc = IFrameObj.contentWindow.document;
} else if (IFrameObj.document) {
// For IE5
IFrameDoc = IFrameObj.document;
} else {
return true;
}

IFrameDoc.location.replace(URL);
/* NB:-
//if you want to create a new iframe dynamically visit
http://developer.apple.com/internet/webcontent/iframe.html
*/
}

The ‘alt’ property does not work with mozilla/firefox

The correct property to use for tooltips is title. The ‘alt’ property has a very important purpose, which is to provide replacement text for images in browsers that cannot or do not (by user’s choice) display images, and if graphical browsers display them as tooltips people will be discouraged from using them for their correct purpose.

for more info https://bugzilla.mozilla.org/show_bug.cgi?id=25537