手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >判断目标是否是window,document,和拥有tagName的Element的代码
判断目标是否是window,document,和拥有tagName的Element的代码
摘要:复制代码代码如下:functionisWindow(obj){if(typeofobj.closed=='undefined')return...

复制代码 代码如下:

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;

}

需要充分测试

【判断目标是否是window,document,和拥有tagName的Element的代码】相关文章:

获取阴历(农历)和当前日期的js代码

微信内置浏览器私有接口WeixinJSBridge介绍

浅谈JavaScript中的Math.atan()方法的使用

在JavaScript中正确引用bind方法的应用

js常用函数 不错

JavaScript代码因逗号不规范导致IE不兼容的问题

js判断鼠标位置是否在某个div中的方法

JQuery分屏指示器图片轮换效果实例

javascript操作表格

jQuery判断一个元素是否可见的方法

精品推荐
分类导航