源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

判断目标是否是window,document,和拥有tagName的Element的代码

  • 时间:2021-12-05 08:03 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:判断目标是否是window,document,和拥有tagName的Element的代码
[u]复制代码[/u] 代码如下:
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; }
需要充分测试
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部