手机
当前位置:查字典教程网 >编程开发 >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的代码】相关文章:

列表内容的选择

光标定位等TextRange的操作的范例代码

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

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

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

jQuery判断指定id的对象是否存在的方法

鼠标划过时整行变色

单击图片时直接出现另存为对话框

javascript操作表格

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

精品推荐
分类导航