To determine whether the target is window,document, and the code _javascript technique that owns the tagname element

Source: Internet
Author: User
Tags tagname
Copy Code code as follows:

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

Need to be fully tested

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.