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

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

javascript原型模式用法实例详解

Js和JQuery获取鼠标指针坐标的实现代码分享

JavaScript判断图片是否已经加载完毕的方法汇总

快速判断某个值是否在select中的方法

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

JS实现简洁、全兼容的拖动层实例

jquery实现的判断倒计时是否结束代码

javascript基础知识分享之类与函数化

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

精品推荐
分类导航