Home > Web Front-end > JS Tutorial > body text

Code to determine whether the target is window, document, and Element with tagName_javascript skills

WBOY
Release: 2016-05-16 18:26:06
Original
1134 people have browsed it
复制代码 代码如下:

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;
}

需要充分测试
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template