Copy codeThe Code is as follows:
Function isWindow (obj)
{
If (typeof obj. closed = 'undefined') return false;
Var result =/\ [object (window | global) \]/I. test (Object. prototype. toString. call (obj ));
If (result) return result;
Try {
Obj. closed = obj. closed;
Return false;
} Catch (e)
{
Result = true;
}
Return result;
}
Function isDocument (obj)
{
If (typeof obj. body = 'undefined') return false;
Var B = obj. body;
Try {
Obj. body = null;
Obj. body = B;
Return false;
} Catch (e)
{
Return true;
}
}
Function isElement (o)
{
Var tn = 'tagname', temp = o [tn], result;
If (typeof temp = 'undefined') return false;
Try {
O [tn] = null;
Result = (temp = o [tn]);
O [tn] = temp;
Return result;
} Catch (e)
{
Return true;
}
}
Function getOwnerWindow (node)
{
If (isWindow (node) return node;
Var doc = isDocument (node )? Node: node. ownerDocument;
Return doc. view | doc. parentWindiw | doc. defaultView;
}
Adequate Testing is required