判斷目標(biāo)是否是window,document,和擁有tagName的Element的代碼
更新時間:2010年05月31日 23:28:39 作者:
判斷目標(biāo)是否是window,document,和擁有tagName的Element的代碼,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:
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;
}
需要充分測試
相關(guān)文章
javascript如何操作HTML下拉列表標(biāo)簽
下拉列表在網(wǎng)站前端開發(fā)中經(jīng)常遇到,如何操作html下拉列表標(biāo)簽,本篇文章給大家詳解javascript如何操作html下拉列表標(biāo)簽,需要的朋友可以來參考下2015-08-08
Javascript怎樣使用SessionStorage和LocalStorage
這篇文章主要介紹了Javascript怎樣使用SessionStorage和LocalStorage,對web存儲數(shù)據(jù)感興趣的同學(xué),可以參考下2021-04-04
JavaScript代碼實現(xiàn)左右上下自動晃動自動移動
最近幾天做了一個項目,原來是用css3動畫做的,由于不兼容IE,改成用js做了,特此分享給大家,供大家參考2016-04-04
關(guān)于js拖拽上傳 [一個拖拽上傳修改頭像的流程]
拖拽是操作系統(tǒng)用戶體驗最偉大的改進之一。它讓人隨心所欲的操作,更符合人們的直觀感受。2011-07-07

